Why do I get ExecutionEngineException on .Net 4.0 Assembly.GetCustomAttributes after installing VS2012 / .Net 4.5?

Easier as the name really is. I updated the solution from .Net 2-3.5 to .Net 4, it worked fine, I installed VS 2012 and .Net 4.5 with it, and now I get an ExecutionEngineException when trying to reflect CustomAttributes attributes from a dynamically generated DLL using the following code:

Assembly assembly = Assembly.LoadWithPartialName("DavesNamespace.Custom"); var attributes = assembly.GetCustomAttributes(typeof(ChecksumAttribute), true); 

I get an exception with the type specified for GetCustomAttributes or without it, but only when it throws an exception, the assembly is loaded successfully, and I can actually view the CustomAttributes collection if I insert a breakpoint.

The original version of .Net 2-3.5 still works since the installation of vs2012.

Any help is much appreciated, I found some vs2012 related questions ending with ExecutionEngineExceptions that look online but nothing with an answer. The problem can be solved by removing VS2012 and .Net 4.5, but since we intend to move to the VS2013 company when it was released this is not really a solution.

EDIT: Got an error that occurs in an example application that does just that, and an exception is thrown anyway, even if the application is created with a setting of 4.5

Stack trace added in comments below (this is null)

+7
c # .net-assembly visual-studio-2012 system.reflection
source share
1 answer

I solved the problem for our specific situation, although I think the root is an undocumented change in the way .Net 4.5 reads CustomAttributes attributes for a DLL.

The solution moved the CustomAttributeBuilder parameter, which was the last before AssemblyBuilder.Save() [after all the assembly content was filled] to the first thing after AppDomain.CurrentDomain.DefineDynamicAssembly() [Before any of the content was filled]

The actual code in which the exception is thrown does not need to be changed, although I will refactorize using the replacement for LoadWithPartialName() , which is just Load(), , this temporary solution still works with LoadWithPartialName() .

Maybe adding a user attribute after the contents of the assembly puts the user attribute in the wrong place? But the problem is with MS to learn.

+1
source share

All Articles