Can the .XmlSerializers.dll assembly generated by SGEN be embedded into the final executable, and still function and provide the performance boost?
Asked
Active
Viewed 252 times
1
-
1I can't think of any reason it would not work, they are loaded as usual with Assembly.Load() so AppDomain.AssemblyResolve is going to fire. Did you even try? What actually went wrong? – Hans Passant Nov 06 '13 at 10:07
-
The problem is I don't know about any simple way to determine whether it provides the performance boost or it doesn't (since it's not very significant). Also, I've heard that .NET might be looking for the actual .DLL File, and if it's not there, it generates the serializers on the fly - which would make having them embedded useless. – Jiri Nov 08 '13 at 12:10
1 Answers
0
I don't think there would be a performance hit on the dll itself. The dll will be loaded in memory anyway as soon it is needed through AssemblyResolve.
After that, whether the dll was found on the disk or grabbed from the exe, since the dll is in-memory, there should have no performance differences at all.
You can embedd the dll in your project by following the directives provided on this stackoverflow answer here.
As for the performances, you could use a Stopwatch, create a loop where you serialize and deserialize the elements X times, then measure the execution time with the 2 methods (one with the dll on disk, one with the dll embedded) to confirm or deny the plausability of this answer.
using System;
using System.Diagnostics;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Thread.Sleep(10000);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
}
}
Source for stopwatch example above: msdn

Community
- 1
- 1

Sage Pourpre
- 9,932
- 3
- 27
- 39