<p>I'm using an XmlSerializer to deserialize a particular type in mscorelib.dll</p>

<pre><code>XmlSerializer ser = new XmlSerializer( typeof( [.Net type in System] ) );
return ([.Net type in System]) ser.Deserialize( new StringReader( xmlValue ) );
</code></pre>

<p>This throws a caught <code>FileNotFoundException</code> when the assembly is loaded:</p>

<blockquote>
  <p>"Could not load file or assembly
  'mscorlib.XmlSerializers,
  Version=2.0.0.0, Culture=neutral,
  PublicKeyToken=b77a5c561934e089' or
  one of its dependencies. The system
  cannot find the file specified."</p>
</blockquote>

<p>FusionLog:</p>

<pre><code>=== Pre-bind state information ===
LOG: User = ###
LOG: DisplayName = mscorlib.XmlSerializers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86
 (Fully-specified)
LOG: Appbase = file:///C:/localdir
LOG: Initial PrivatePath = NULL
Calling assembly : System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\localdir\bin\Debug\appname.vshost.exe.Config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: mscorlib.XmlSerializers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86
LOG: Attempting download of new URL file:///C:/localdir/bin/Debug/mscorlib.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///C:/localdir/bin/Debug/mscorlib.XmlSerializers/mscorlib.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///C:/localdir/bin/Debug/mscorlib.XmlSerializers.EXE.
LOG: Attempting download of new URL file:///C:/localdir/bin/Debug/mscorlib.XmlSerializers/mscorlib.XmlSerializers.EXE.
</code></pre>

<p>As far as I know there is no mscorlib.XmlSerializers.DLL, I think the DLL name has bee auto generated by .Net looking for the serializer. </p>

<p>You have the option of creating a myApplication.XmlSerializers.DLL when compiling to optimise serializations, so I assume this is part of the framework's checking for it.</p>

<p>The problem is that this appears to be causing a delay in loading the application - it seems to hang for a few seconds at this point.</p>

<p>Any ideas how to avoid this or speed it up?</p>

[{'answer_id': 12136, 'author': 'Will Dean', 'author_id': 987, 'author_profile': 'https://Stackoverflow.com/users/987', 'pm_score': 2, 'selected': False, 'text': "<p>The delay is because, having been unable to find the custom serializer dll, the system is building the equivalent code (which is very time-consuming) on the fly.</p>\n\n<p>The way to avoid the delay is to have the system build the DLL, and make sure it's available to the .EXE - have you tried this?</p>\n"}, {'answer_id': 12160, 'author': 'Will Dean', 'author_id': 987, 'author_profile': 'https://Stackoverflow.com/users/987', 'pm_score': 3, 'selected': True, 'text': "<p>I'm guessing now. but:</p>\n\n<ol>\n<li>The system might be generating a serializer for the whole of mscorlib, which could be very slow.</li>\n<li>You could probably avoid this by wrapping the system type in your own type and serialising that instead - then you'd get a serializer for your own assembly.</li>\n<li>You might be able to build the serializer for mscorlib with sgen.exe, which was the old way of building serializer dlls before it got integrated into VS.</li>\n</ol>\n"}, {'answer_id': 953571, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Okay, so I ran into this problem and have found a solution for it specific to my area.</p>\n\n<p>This occurred because I was trying to serialize a list into an XML document (file) without an XML root attribute.  Once I added the following files, the error goes away.</p>\n\n<pre><code>XmlRootAttribute rootAttribute = new XmlRootAttribute();\nrootAttribute.ElementName = "SomeRootName";\nrootAttribute.IsNullable = true;\n</code></pre>\n\n<p>Dunno if it\'ll fix your problem, but it fixed mine.</p>\n'}]
['https://Stackoverflow.com/questions/12135', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/905/']