I have recently installed Visual Studio 2012.
However, after the installation, a project that was previously working correctly in Visual Studio 2010 began throwing and crashing on the following error:
'System.TypeInitializationException: The type initializer for 'MyType' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'MyAssembly.XmlSerializers' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
I did not upgrade the project to VS2012, I am running it out of VS2010 as before. I have not made any changes to the project itself. The only change was that I installed VS2012 (and .NET 4.5) on the machine.
What could be causing this unexpected problem?
The situation was a little trickier than I had expected. The XMLSerializers DLL for that assembly seems to be essential for authentication in my solution, and just "Press[ing] F5 to continue running until the real problem occurs" did not lead to some unrelated error.
I have not been able to completely understand what the underlying issue is, but it seems that there is a problem creating the DLL dynamically after Visual Studio is upgraded.
The way I have worked around the issue is by running the sgen tool to manually create the serializers and setting the flag "Generate Serialization Assemblies" to Off. The process can be automated by adding a post-build instruction to run the tool.
That being said, I have no idea why this issue comes up in the first place, as I am certain that I did not open the project in VS2012.