none
How to get rid of System.ExecutionEngineException in managed COM object using CLR 4.0 and VS2012 installed?

    Question

  • Hi,

    I try to create some managed COM objects to be used in unmanaged code.
    All works fine when compiling for CLR2.0 (e.g. Framework 3.5).
    But as asson as I compile for CLR4.0 (Framwork 4.0) exception hanlding does not longer work on machines where VS2012 is installed.
    On machines where VS2012 is installed any managed exception is followed by a System.ExecutionEngineException, hwich should no longer be used, shouldn't it?

    Here my code:
    unmanaged Delphi code calling:

    var comClass:IComClass;
    begin
      comClass := CoComClass.Create();
      comClass.TriggerIt();
    

    managed code:

        [ComVisible(true)]
        [Guid("C3437B87-7FCC-4F63-9AE9-FF462B03C255")]
        public interface IComClass
        {
            void TriggerIt();     
        }
    
        [ComVisible(true)]
        [Guid("C3437B87-7FCC-4F63-9AE9-FF462B03C256")]
        [ClassInterface(ClassInterfaceType.None), ComDefaultInterface(typeof(IComClass))]
        public class ComClass : IComClass
        {  
            public void TriggerIt()
            {
                InternalInit();
                System.Windows.Forms.MessageBox.Show(Assembly.GetExecutingAssembly().ImageRuntimeVersion+Environment.NewLine+Environment.Version.ToString());                     
                throw new Exception("TEST Exception");
            }
       
            internal static void InternalInit()
            {
                // add application exception handlers
                System.Windows.Forms.Application.ThreadException += Application_ThreadException;
                try
                {
                    System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.ToString());
                }
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            }
    
            private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
            {
                CurrentDomain_UnhandledException(sender, new UnhandledExceptionEventArgs(e.Exception, true));
            }
    
            private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
            {
                MessageBox.Show("CurrentDomain_UnhandledException Hander!!!");
            }
        }

    As you may see I expect to see a messageBox showing "CurrentDomain_UnhandledException Hander!!!" in any case.
    That boy is shown when build the managed code against CLR2.0.
    But it is no longer shown when building against CLR4.0 and VS2012 is installed on the system.

    Trying to debug the issue using VS2012 shows that my test exception is directly followed by a System.ExecutionEngineException.

    Any ideas how to solve this?


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com

    Thursday, January 10, 2013 11:00 AM

All replies

  • Hi Harald,

    According to your description, I'd like to move this thread to CLR forum for better support, where more experts live.

    Thanks for your understanding.


    Bob Shen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, January 11, 2013 7:02 AM
  • Hi Jam,

    Welcome to the MSDN Forum.

    According to the MSDN document: http://msdn.microsoft.com/en-us/library/system.executionengineexception.aspx

    In some cases, an application that targets the .NET Framework may throw an ExecutionEngineException exception during garbage collection when an application or the system on which it is running is under a heavy load. As a workaround, you can disable concurrent garbage collection by modifying the application's configuration file. For more information, see How to: Disable Concurrent Garbage Collection.

    Would you like to try this way first?

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 11, 2013 7:46 AM
  • Hello Mike,

    thank you for your answer, but that can't be the solution.
    No program but the test program is running when this occurs. (VS2012 is installed but not running) 
    And it does not occur on systems where no VS2012 is installed.
    So VS2012 seems to modify the CLR.
    Also the documentation of System.ExecutionEngineException sais:

    "This type previously indicated an unspecified fatal error in the runtime. The runtime no longer raises this exception so this type is obsolete."

    http://msdn.microsoft.com/de-de/library/system.executionengineexception(v=vs.100).aspx

    So either the documentation is wrong or the VS2012 installation mixes up the the two CLR versions.


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com

    Friday, January 11, 2013 8:01 AM
  • Hi Harald,

    OK, I got it, and I am trying to involve some other one into this case. Wait it patiently please.

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 11, 2013 9:35 AM
  • Hi,

    any news on this issue?


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com

    Wednesday, January 16, 2013 1:17 PM
  • I can't reproduce a System.EngineExecutionException. Using your C# com object, I created a simple C++ console app to call it. I called it with both CLR 4.5 and CLR 2 and got identical behavior.
    Thursday, January 17, 2013 1:45 AM
  • Hi,

    here my demo project: DotNetComClassLibrary.zip

    I includes the compiled unmanaged exe doing nothing else but 

    var comClass:IComClass;
    begin
      comClass := CoComClass.Create();
      comClass.TriggerIt();

    and the compiled .Net lib as well as its source.

    You should be able to reproduce it with this.

    When I copy the compiled files to other machines I can reproduce it like described above:
    as soon as a VS2012 is installed it crashes. (Tested on 3 machines with VS2012 and on three without, beside mine)
    If you change the target framework from 4.0 to 3.5 it works fine on all 7 machines.


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com



    Thursday, January 17, 2013 8:37 AM
  • I still don't see that exception. However, running under windbg I can see a long recursion of c0000025 exceptions. There's quite a few hits on this involving Delphi.

    I get the same behavior with the .NET 3.5 build:

    ...

    (19ec.33e8): Unknown exception - code c0000025 (first chance)
    (19ec.33e8): Unknown exception - code c0000025 (first chance)
    (19ec.33e8): Unknown exception - code c0000025 (first chance)
    (19ec.33e8): Unknown exception - code c0000025 (first chance)
    (19ec.33e8): Unknown exception - code c0000025 (first chance)
    (19ec.33e8): Unknown exception - code c0000025 (first chance)
    (19ec.33e8): Unknown exception - code c0000025 (first chance)
    (19ec.33e8): Unknown exception - code c0000025 (first chance)
    (19ec.3240): Break instruction exception - code 80000003 (first chance)
    eax=7efa3000 ebx=00000000 ecx=00000000 edx=778ff85a esi=00000000 edi=00000000
    eip=7787000c esp=06c9ff5c ebp=06c9ff88 iopl=0         nv up ei pl zr na pe nc
    cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000246
    ntdll!DbgBreakPoint:
    7787000c cc              int     3
    0:007> lmvm mscorwks
    start    end        module name
    79110000 796bc000   mscorwks   (deferred)            
        Image path: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
        Image name: mscorwks.dll
        Timestamp:        Wed Aug 29 22:58:45 2012 (503F0115)
        CheckSum:         005B31F9
        ImageSize:        005AC000
        File version:     2.0.50727.5466
        Product version:  2.0.50727.5466
        File flags:       0 (Mask 3F)
        File OS:          4 Unknown Win32
        File type:        2.0 Dll
        File date:        00000000.00000000
        Translations:     0409.04b0
        CompanyName:      Microsoft Corporation
        ProductName:      Microsoft® .NET Framework
        InternalName:     mscorwks.dll
        OriginalFilename: mscorwks.dll
        ProductVersion:   2.0.50727.5466
        FileVersion:      2.0.50727.5466 (Win7SP1GDR.050727-5400)
        FileDescription:  Microsoft .NET Runtime Common Language Runtime - WorkStation
        LegalCopyright:   © Microsoft Corporation.  All rights reserved.
        Comments:         Flavor=Retail

    Thursday, January 17, 2013 11:29 PM
  • Right, I did not try WinDbg.
    I only get the System.ExecutionEngineException when trying to debug using VS.

    Now I also noted:
    When compiled to 3.5 I can see the expected MessageBox.
    But when I'm attached with WinDbg I don't see that MessageBox.

    So if you start the 3.5 compiled version without any debugger attached, do you see the MessageBox?

    Did you try my compiled version and execute it on a machine where no VS2012 is installed and on a machine where VS2012 ist installed without attaching any debugger?

    I still expect to see the MessageBox. I know it craches after the messagebox in any case but that's not the point.


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com

    Monday, January 21, 2013 3:45 PM
  • .NET 4.5:

    'Project3.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Symbols loaded.
    'Project3.exe' (Managed (v4.0.30319)): Loaded 'D:\cases\113011410134476\repro\DotNetComClassLibrary.dll', Symbols loaded.
    'Project3.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Symbols loaded.
    'Project3.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Symbols loaded.
    'Project3.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Symbols loaded.
    A first chance exception of type 'System.Exception' occurred in DotNetComClassLibrary.dll
    Additional information: TEST Exception
    'Project3.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
    'Project3.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Symbols loaded.
    'Project3.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Symbols loaded.
    The program '[0x2484] Project3.exe: Managed (v4.0.30319)' has exited with code -1073741819 (0xc0000005) 'Access violation'.

    Rebuild with .NET 3.5, and I get a very long pause after the version dialog and then the app exits -- with no Debug window output.

    Also, if I enable native debugging in VS (4.0 build), I see the vast stream of 0XC0000025 exceptions. I suspect that the exception you are seeing is peculiar to your system, probably as a result of this blast of first chance exceptions in ntdll.dll.  In fact, the AV noted above is coming from the CLR, trying to build an error string for Watson reporting. Do you by any chance have Watson error reporting turned off? You could have a different failure mode.

    I don't have a 4.0 system at hand to test. Since I can't repro the error, or the non-error on 3.5, I'm not sure building a clean 4.0 system to verify no error is necessary.

    Can you reproduce this without a Delphi EXE? It could be generating invalid stack unwind info, which seems likely with the native exceptions noted.

    Tuesday, January 22, 2013 11:42 PM
  • Hello Steve,
    " I suspect that the exception you are seeing is peculiar to your system", no, as I wrote before, I can reproduce this on several machines.
    " Do you by any chance have Watson error reporting turned off?", off cause, that's the point, the error does not orrcur on machines where no VS2012 is installed, and as soon as it is installed it replaces Watson as JitDebugger and then I no longer see the second messagebox.

    Never mind, but I think I'm going to open a ticket for this issue.


    Best regards,
     
    Harald Binkle


    Exchange Server Toolbox | SmartPOP2Exchange | SpamAssassin
    JAM Software GmbH
    Am Wissenschaftspark.26 * 54296 Trier * Germany
    http://www.jam-software.com

    Wednesday, January 23, 2013 9:41 AM