locked
Why am I getting ExecutionEngineException on .Net 4.0 Assembly.GetCustomAttributes after installing VS2012/.Net 4.5? RRS feed

  • Question

  • User-727603129 posted

    As simple as title really. I've upgraded a solution from .Net 2-3.5 to .Net 4, it worked fine, I've then installed VS 2012 and with it .Net 4.5 and I'm now getting an ExecutionEngineException when trying to reflect the CustomAttributes from a dynamically generated DLL using the following code:

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

    I get the exception with or without the Type specified for GetCustomAttributes, but it's only at that point that it throws the exception, the assembly is successfully loaded and I can actually view the CustomAttributes collection if I stick a break point in.

    The original .Net 2-3.5 version still works since having installed vs2012.

    Any help much appreciated, I have found a few issues stemming from vs2012 ending with ExecutionEngineExceptions looking online, but nothing with an answer. The problem can be resolved by removing VS2012 and .Net 4.5, but as we're intending to move to VS2013 company wide when it's released that's not really a solution.

    Tuesday, July 23, 2013 11:18 AM

All replies

  • User-1008337648 posted

    Hi mckjerral,

    According to your description, the program worked fine in .net 2-3.5 environment, however run with ExecutionEngineException in .net4.5 environment. The exception that is thrown when there is an internal error in the execution engine of the common language runtime. Please provide more detail error informations, then we can solve the issue better. 

    As follows may help you:

    A. Repair your vs2012 or upgraded to vs2012 update3

    Thanks

    Best Regards

    Wednesday, July 24, 2013 10:52 PM
  • User-1008337648 posted

    Hi mckjerral,

    As follows is my code:

    namespace AssemblyTest
    {
        [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
        [ComVisible(true)]
        public sealed class ChecksumAttribute:Attribute
        {
    
            string someText;
            public ChecksumAttribute() : this(string.Empty) {}
            public ChecksumAttribute(string txt) { someText = txt; }
    
            public string SomeText
            {
                get{
                    return someText;
                }
            }
    
        }
    }
    
    [assembly: ChecksumAttribute("This is my testAssembly")]
    namespace AssemblyTest
    {
        public class Class1
        {
        }
    }
    using AssemblyTest;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                GetTestAssembly2();
                
                Console.ReadLine();
    
            }
    
           private static void GetTestAssembly2()
            {
                Type clsType = typeof(Class1); // Get the assembly object. Assembly assy = clsType.Assembly; //Assembly assembly = Assembly.LoadWithPartialName("AssemblyTest.Clas1");             //1
                var attributes = assy.GetCustomAttributes(typeof(ChecksumAttribute), true);
                Console.WriteLine(((ChecksumAttribute)attributes.First()).SomeText);
                //2
                ChecksumAttribute adAttr =
                        (ChecksumAttribute)Attribute.GetCustomAttribute(
                        assy, typeof(ChecksumAttribute));
                Console.WriteLine(adAttr.SomeText);
            }
        }
    }

    Please try it

    Thanks

    Best Regards

    Thursday, July 25, 2013 1:33 AM
  • User-727603129 posted

    I'm already on VS2012 Update 3, I'm inclined to think it is 4.5 not VS2012 that is causing the issue

    Thursday, July 25, 2013 3:42 AM
  • User-727603129 posted

    That code would work for me, I can inspect assemblies compiled in VS, just not the dynamically created one.

    I've even stripped out all the content of the dynamic DLL and it still can't reflect the attributes.

    Thursday, July 25, 2013 3:44 AM
  • User-1008337648 posted

    Hi mckjerral,

    I can't anderstand better that you said " I can inspect assemblies compiled in VS, just not the dynamically created one".

    Is it mean only use this code in "AssemblyInfo.cs":

    using AssemblyTest;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    
    // General Information about an assembly is controlled through the following 
    // set of attributes. Change these attribute values to modify the information
    // associated with an assembly.
    [assembly: AssemblyTitle("AssemblyTest")]
    [assembly: AssemblyDescription("AssemblyTest")]
    [assembly: AssemblyConfiguration("")]
    [assembly: AssemblyCompany("")]
    [assembly: AssemblyProduct("AssemblyTest")]
    [assembly: AssemblyCopyright("Copyright ©  2013")]
    [assembly: AssemblyTrademark("")]
    [assembly: AssemblyCulture("")]
    [assembly: ChecksumAttribute("This is my testAssembly")]

    If so we can also use the same code to get the "ChecksumAttribute" information.

    By the way the "System.Reflection.Assembly.LoadWithPartialName(string) is obsolete. we can use "typeof(Class1).Assembly" to get Assembly instance. For more infomation, please refer to http://msdn.microsoft.com/en-us/library/ee461502.aspx

    Thanks

    Best Regards

    Thursday, July 25, 2013 11:35 PM
  • User-727603129 posted

    LoadWithPartialName is deprecated, but Assembly.Load has the same signature and using that doesn't change the functionality, or prevent this issue occurring.

    This is nothing to do with ChecksumAttribute, that is a custom attribute that I created, but even if I remove that being set and the parameter to only read ChecksumAttribute from GetCustomAttributes it makes no difference.

    This is a dynamically generated DLL, created at runtime using AssemblyBuilder, I am able to read the CustomAttributes collection of a DLL built by visual studio, but not the dynamically generated one.

    Monday, July 29, 2013 6:58 AM
  • User433674817 posted

    According to the following article LoadWithPartialName  is obsolete

    http://msdn.microsoft.com/en-us/library/12xc5368.aspx

    However we do see that you are seeing the same behavior with Load method. I do see that your application is running in .net 3.5. Check in your web.config if you dont' have any binding redirect for .net 3.5 etc.

    If not then please open up a case with us for further troubleshooting.

    Monday, August 19, 2013 7:03 PM