6
votes

I am building a solution which contains several solutions. All but one of them build without any problems. The problematic one emits the following message:

Error 2 Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. J:\MyPlugins\MyPlugin1\SGEN MyPlugin1

I turned on the verbose output in Visual Studio and I got the following: C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\sgen.exe /assembly:

I checked the output with FusionLog and everything loaded correctly. This turned out to be a red herring. I decided to run the build again with the verbosity turned up. I got the following:

Microsoft (R) Xml Serialization support utility [Microsoft (R) .NET Framework, Version 4.0.30319.17929] Copyright (C) Microsoft Corporation. All rights reserved. If you would like more help, please type "sgen /?". SGEN : error : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. The command exited with code 1. Done executing task "SGen" -- FAILED.

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\sgen.exe /assembly:":\MyPlugins\MyPlugin1.dll" /proxytypes /reference:"J:\MyPlugins\MyPlugin1\packages\FluentValidation.3.4.6.0\lib\Net40\FluentValidation.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll" /reference:"J:\MyPlugins\MyPlugin1\Libraries\Core\bin\Release\Core.dll" /reference:"J:\MyPlugins\MyPlugin1\Libraries\Services\bin\Release\Services.dll" /reference:"J:\MyPlugins\MyPlugin1\Presentation\Web.Framework\bin\Release\Web.Framework.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.EnterpriseServices.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.dll" /reference:"C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.Services.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Xml.dll"

What is causing this error and how do I fix it short of turning off SGEN? FYI, I didn't write the code.

3
Did you ever find an answer to this? I've got the same problemcsharpforevermore
See my answer. Thanks for reminding me.ATL_DEV

3 Answers

13
votes

A great tip that worked for me, taken from here: http://hashtagfail.com/post/5255977780/sgen-loaderexceptions-error

The reason why this happens is that in Release builds, Visual Studio attempts to generate a serialization assembly containing the types in your solution, to improve XmlSerializer serialization performance, should you choose to serialize your types. This can be disabled by going to the Build tab of the project properties and setting “Generate serialization assembly” to “Off”.

1
votes

I had the same problem and it was a bad reference in the project. After deleting the DLL from the GAC, it was working fine. You can find the problem DLL with Fusion Log. More info here

0
votes

The solution is straightforward but hard to find. You must delete the asp.net precompiled folder. Since plugins are dynamically referenced, .NET can't update it's dlls as it would other components.