none
Creating COM class and calling method in static constructor of .net 4.0 in C# is crashing the application RRS feed

  • Question

  • I am facing problem with static constructor in .net 4.0. The same code works fine with 3.5.

    I have static constructor in my assembly. My Assembly referenced in an application and static method is called in the Main() method of the executable. 

    When I call a static method from Main(), Static constructor called and tries to create RCW COM object and calls COM method. It is crashing in side the un managed  code with UnKnownException.

    If I call the same static method, by creating a Thread from Main() and call from the new thread, then it works fine.

    Sample class:

    Public sealed class LicenseCheck

    {

            static LicenseCheck()

           {

                    checker = new CHECKLib.CheckerClass(); //This is COM class
                    checker.SetLicenseLocation(path); // Calling this method is crashing.

    }

           //Calling this static method from Application's Main() causes crash.

    public static bool CheckOption(string optionName)

    {

            //Access some static variable.

    }

    }

    //!DumpStack information of crashing Main() thread.

    0:000> ~0 e !dumpstack
    OS Thread Id: 0x2bf0 (0)
    Current frame: ntdll!ZwWaitForSingleObject+0xa
    Child-SP         RetAddr          Caller, Callee
    000000000043c470 00000000776a5af2 ntdll!RtlReportExceptionEx+0x1d2, calling ntdll!NtWaitForSingleObject
    000000000043c490 000007fef8527e45 clr! ?? ::FNODOBFM::`string'+0xe5f75, calling clr!CORDebuggerAttached
    000000000043c560 00000000776a5c95 ntdll!RtlReportException+0xb5, calling ntdll!RtlReportExceptionEx
    000000000043c580 000007fef82fb3bf clr!CLRVectoredExceptionHandlerPhase2+0xb0, calling clr!CantAllocThreads::UnmarkThread
    000000000043c5e0 00000000776a5cfa ntdll!RtlpTerminateFailureFilter+0x1a, calling ntdll!RtlReportException
    000000000043c610 00000000776a6b35 ntdll!RtlReportCriticalFailure+0x96, calling ntdll!RtlpTerminateFailureFilter
    000000000043c618 00000000776a6ae2 ntdll!RtlReportCriticalFailure+0x62, calling ntdll!RtlRaiseException
    000000000043c620 0000000077614dc1 ntdll!RtlLookupFunctionTable+0xbd, calling ntdll!RtlReleaseSRWLockShared
    000000000043c640 00000000775f4f58 ntdll!_C_specific_handler+0x8c
    000000000043c670 00000000775f88e6 ntdll!RtlpCallVectoredHandlers+0xe3, calling ntdll!RtlReleaseSRWLockExclusive
    000000000043c6a0 00000000776a6ae2 ntdll!RtlReportCriticalFailure+0x62, calling ntdll!RtlRaiseException
    000000000043c6b0 0000000077614f4d ntdll!RtlpExecuteHandlerForException+0xd
    000000000043c6e0 00000000775f5b3c ntdll!RtlDispatchException+0x3cb, calling ntdll!RtlpExecuteHandlerForException
    000000000043c710 000007feecc757ea *** ERROR: Symbol file could not be found.  Defaulted to export symbols for AcXtrnal.dll - 
    AcXtrnal+0x57ea, calling AcXtrnal!GetHookAPIs+0x2050
    000000000043c778 00000000776a6ae2 ntdll!RtlReportCriticalFailure+0x62, calling ntdll!RtlRaiseException
    000000000043c7e0 000007feecc757ea AcXtrnal+0x57ea, calling AcXtrnal!GetHookAPIs+0x2050
    000000000043c8c0 00000000776a71a6 ntdll!RtlpReportHeapFailure+0x26, calling ntdll!RtlReportCriticalFailure
    000000000043cab0 000007fef80f4352 clr!HashMap::LookupValue+0x157, calling clr!GCHolder<1,0,1>::~GCHolder<1,0,1>
    000000000043cb40 000007fef825ae99 clr!PtrHashMap::Gethash+0x9, calling clr!HashMap::Gethash
    000000000043cb60 000007fef80f3db1 clr!CrstBase::Leave+0x31, calling clr!GetThread
    000000000043cb70 000007fef80fdb7c clr!HashMap::InsertValue+0xff, calling clr!GCHolder<1,0,1>::~GCHolder<1,0,1>
    000000000043cb90 000007fef80f46f4 clr!Holder<CrstBase * __ptr64,&CrstBase::AcquirePreempLock,&CrstBase::ReleaseLock,0,&CompareDefault<CrstBase * __ptr64>,1>::~Holder<CrstBase * __ptr64,&CrstBase::AcquirePreempLock,&CrstBase::ReleaseLock,0,&CompareDefault<CrstBase * __ptr64>,1>+0x24, calling clr!CrstBase::Leave
    000000000043cbd0 000007fef825ce3d clr!RCWCache::FindOrInsertWrapper+0x10f, calling clr!ComCallWrapperCache::LockHolder::~LockHolder
    000000000043cc70 000007fef825c125 clr!MethodTable::IsExtensibleRCW+0x11, calling clr!MethodTable::GetClass
    000000000043cce0 000007fef8268b05 clr!SafeQueryInterface+0x81, calling clr!GCHolder<0,0,0>::~GCHolder<0,0,0>
    000000000043cd20 000007fef81acdf7 clr!SafeReleaseHelper+0xb7, calling clr!GetThread
    000000000043cd60 000007fef810d5f3 clr!FrameWithCookie<GCFrame>::FrameWithCookie<GCFrame>+0x43, calling clr!GetThread
    000000000043cd90 00000000775f5f18 ntdll!RtlRaiseException+0x48, calling ntdll!RtlCaptureContext
    000000000043cdc0 00000000775f610e ntdll!RtlRaiseException+0x221, calling ntdll!RtlDispatchException
    000000000043ce68 000007ff00218191 (MethodDesc 000007ff000383c8 +0x3f1 Philips.PmsCT.Base.Licensing.LicenseCheck..cctor())
    000000000043cef0 00000000776a6ae2 ntdll!RtlReportCriticalFailure+0x62, calling ntdll!RtlRaiseException
    000000000043d0c0 000007ff00218191 (MethodDesc 000007ff000383c8 +0x3f1 Philips.PmsCT.Base.Licensing.LicenseCheck..cctor())
    000000000043d2b0 000007fef80f4db5 clr!MetaSig::MetaSig+0x105, calling clr!SigParser::SkipExactlyOne
    000000000043d2d0 000007fef80f4a04 clr!MethodDesc::GetModule+0x15, calling clr!IBCLogger::InstrEnabled
    000000000043d2e0 000007feecc757ea AcXtrnal+0x57ea, calling AcXtrnal!GetHookAPIs+0x2050
    000000000043d300 000007fef80f536e clr!MetaSig::MetaSig+0x24e, calling clr!memcpy
    000000000043d340 000007fef80f5897 clr!ClassLoader::LoadTypeDefOrRefThrowing+0x350, calling clr!TypeHandle::GetLoadLevel
    000000000043d400 00000000776a6ae2 ntdll!RtlReportCriticalFailure+0x62, calling ntdll!RtlRaiseException
    000000000043d438 00000000776a6ae2 ntdll!RtlReportCriticalFailure+0x62, calling ntdll!RtlRaiseException
    000000000043d490 0000000077628839 ntdll!RtlpGetModifiedProcessCookie+0x35, calling ntdll!RtlUniform
    000000000043d4d0 00000000776a71a6 ntdll!RtlpReportHeapFailure+0x26, calling ntdll!RtlReportCriticalFailure
    000000000043d500 00000000776a84d2 ntdll!RtlpHeapHandleError+0x12, calling ntdll!RtlpReportHeapFailure
    000000000043d530 00000000776a9e64 ntdll!RtlpLogHeapFailure+0xa4, calling ntdll!RtlpHeapHandleError
    000000000043d560 000000007764c105 ntdll! ?? ::FNODOBFM::`string'+0x11e9c, calling ntdll!RtlpLogHeapFailure
    000000000043d5e0 000007feecc77e5f AcXtrnal+0x7e5f
    000000000043d7e0 000000001afe110c *** WARNING: Unable to verify checksum for LicCheck.ocx
    *** ERROR: Symbol file could not be found.  Defaulted to export symbols for LicCheck.ocx - 
    LicCheck+0x110c, calling LicCheck!DllUnregisterServer+0x3930
    000000000043d810 000007fef80f1f37 clr!DoCLRToCOMCall+0x177
    000000000043d8b0 000007fef1465835 (MethodDesc 000007fef1461f58 +0x115 DomainBoundILStubClass.IL_STUB_CLRtoCOM(System.String))
    000000000043d9b8 000007fef1465835 (MethodDesc 000007fef1461f58 +0x115 DomainBoundILStubClass.IL_STUB_CLRtoCOM(System.String))
    000000000043da30 000007ff00218191 (MethodDesc 000007ff000383c8 +0x3f1 Philips.PmsCT.Base.Licensing.LicenseCheck..cctor())
    000000000043dbd0 000007fef81a90b4 clr!CallDescrWorker+0x84
    000000000043dbf0 000007fef80fc8d0 clr!MetaSig::NextArg+0x4d, calling clr!SigParser::SkipExactlyOne
    000000000043dc10 000007fef81a91c9 clr!CallDescrWorkerWithHandler+0xa9, calling clr!CallDescrWorker
    000000000043dc20 000007fef8113b79 clr!FieldDesc::GetFieldTypeHandleThrowing+0x86, calling clr!_security_check_cookie
    000000000043dc90 000007fef81ab4a4 clr!DispatchCallDebuggerWrapper+0x74, calling clr!CallDescrWorkerWithHandler
    000000000043dcd0 000007fef810d54f clr!AllocateObject+0x9c
    000000000043dd30 000007fef81b17bf clr!MethodTable::RunClassInitEx+0x1ff, calling clr!DispatchCallDebuggerWrapper
    000000000043ddf0 000007fef80f3f6e clr!CrstBase::Enter+0xc7, calling clr!GetThread
    000000000043de00 000007fef80f3db1 clr!CrstBase::Leave+0x31, calling clr!GetThread
    000000000043de40 000007fef81a8530 clr!CrstBase::Enter+0x11e, calling clr!Thread::DisablePreemptiveGC
    000000000043de80 000007fef81b1488 clr!MethodTable::DoRunClassInitThrowing+0x55e, calling clr!MethodTable::RunClassInitEx
    000000000043deb0 0000000077631885 ntdll!RtlFreeHeap+0x1a2, calling ntdll!RtlpFreeHeap
    000000000043df30 000007feecc77e5f AcXtrnal+0x7e5f
    000000000043e030 000007fef5d02cf1 clrjit!PreJit::compileMethod+0x128, calling clrjit!operator delete
    000000000043e040 000007fef815bf70 clr!CEEInfo::MethodCompileComplete+0x21, calling clr!GetThread
    000000000043e0b0 000007fef8169889 clr!invokeCompileMethodHelper+0xdd
    000000000043e140 000007fef816978f clr!invokeCompileMethod+0x6f, calling clr!GCHolder<0,0,0>::~GCHolder<0,0,0>
    000000000043e1e0 000007fef81c3860 clr!COMNlsInfo::InternalGetGlobalizedHashCode+0x1e1, calling clr!_security_check_cookie
    000000000043e360 000007fef80f3f6e clr!CrstBase::Enter+0xc7, calling clr!GetThread
    000000000043e3a0 000007fef80f7276 clr!CExecutionEngine::AcquireLock+0x47, calling clr!CrstBase::Enter
    000000000043e3c0 000007fef80f72ad clr!ClrEnterCriticalSection+0xe, calling clr!GetExecutionEngine
    000000000043e410 000007fef81a094d clr!MDInternalRO::GetDefaultValue+0x14e, calling clr!_FillMDDefaultValue
    000000000043e440 000007fef6cd12d7 nlssorting!SortCompareString+0x2b7, calling nlssorting!_security_check_cookie
    000000000043e480 000007fef6cd12d7 nlssorting!SortCompareString+0x2b7, calling nlssorting!_security_check_cookie
    000000000043e4f0 000007fef810d770 clr!StubHelpers::BeginStandalone+0x80, calling clr!SF_IsStubWithDemand
    000000000043e5a0 000007fef81a736d clr!COMNlsInfo::InternalCompareString+0x11f
    000000000043e630 000007fef80f17c7 clr!DoNDirectCall__PatchGetThreadCall+0x7b
    000000000043e680 000007fef6cd2b0f nlssorting!SortChangeCase+0x12e, calling nlssorting!MapCase
    000000000043e6c0 000007fef825fdf3 clr!SortVersioning::SortDllChangeCase+0x47
    000000000043e710 000007fef81beb49 clr!COMNlsInfo::InternalChangeCaseString+0x269, calling clr!HelperMethodFrameRestoreState
    000000000043e810 000007fef80f3f6e clr!CrstBase::Enter+0xc7, calling clr!GetThread
    000000000043e820 000007fef80f3db1 clr!CrstBase::Leave+0x31, calling clr!GetThread
    000000000043e850 000007fef81ab75f clr!DomainLocalModule::SetClassFlags+0xcb, calling clr!CrstBase::Leave
    000000000043e8a0 000007fef80f3db1 clr!CrstBase::Leave+0x31, calling clr!GetThread
    000000000043e8d0 000007fef81aac97 clr!DomainLocalModule::PopulateClass+0x12c, calling clr!CrstBase::Leave
    000000000043e8f0 000007fef8158301 clr!MethodDesc::IsDomainNeutral+0xa1
    000000000043e940 000007fef81ab660 clr!MethodTable::CheckRunClassInitThrowing+0xe3, calling clr!MethodTable::DoRunClassInitThrowing
    000000000043e970 000007fef82bfebc clr!MethodDesc::DoPrestub+0x587, calling clr!MethodTable::CheckRunClassInitThrowing
    000000000043e9b0 000007fef7123a69 (MethodDesc 000007fef6ef1c08 +0x9 System.RuntimeTypeHandle.IsPrimitive(System.RuntimeType)), calling 000007fef81b30d0 (stub for System.RuntimeTypeHandle.GetCorElementType(System.RuntimeType))
    000000000043ea20 000007fef61604a9 (MethodDesc 000007fef5f7b638 +0x99 System.Configuration.ApplicationSettingsBase.get_Item(System.String)), calling 000007fef80f31d0 (stub for System.Threading.Monitor.Exit(System.Object))
    000000000043ea80 000007fef81aa5e3 clr!PreStubWorker+0x1df, calling clr!MethodDesc::DoPrestub
    000000000043eb40 000007fef80f2d07 clr!ThePreStubAMD64+0x87, calling clr!PreStubWorker
    000000000043ec10 000007ff00200171 (MethodDesc 000007ff00034190 +0x51 AVA.Program.Main()), calling 000007ff0003c260 (stub for Philips.PmsCT.Base.Licensing.LicenseCheck.CheckOption(System.String))
    000000000043ecd0 000007fef81a90b4 clr!CallDescrWorker+0x84
    000000000043ece0 000007fef80f4db5 clr!MetaSig::MetaSig+0x105, calling clr!SigParser::SkipExactlyOne
    000000000043ed10 000007fef81a91c9 clr!CallDescrWorkerWithHandler+0xa9, calling clr!CallDescrWorker
    000000000043ed90 000007fef81a9245 clr!MethodDesc::CallDescr+0x2a1, calling clr!CallDescrWorkerWithHandler
    000000000043ee00 000007fef81b0256 clr!MethodDesc::CallDescr+0xed, calling clr!_chkstk
    000000000043eed0 000007fef81a7b8d clr!Frame::Pop+0xe, calling clr!GetThread
    000000000043eef0 000007fef82136d7 clr!MethodDesc::GetSigPointer+0x18, calling clr!MethodDesc::GetSig
    000000000043efc0 000007fef82131d1 clr!ClassLoader::RunMain+0x228, calling clr!MethodDesc::CallDescr
    000000000043f050 000007feecc757ea AcXtrnal+0x57ea, calling AcXtrnal!GetHookAPIs+0x2050
    000000000043f170 000007fef81a7b8d clr!Frame::Pop+0xe, calling clr!GetThread
    000000000043f190 000007fef82136d7 clr!MethodDesc::GetSigPointer+0x18, calling clr!MethodDesc::GetSig
    000000000043f1d0 000007fef8268883 clr!Thread::SetBackground+0x87, calling clr!ThreadStore::UnlockThreadStore
    000000000043f210 000007fef821330c clr!Assembly::ExecuteMainMethod+0xac, calling clr!ClassLoader::RunMain
    000000000043f350 000007feecc77e5f AcXtrnal+0x7e5f
    000000000043f380 000007fef81ee20a clr!AppDomain::GetFriendlyNameForDebugger+0x82, calling clr!SString::GetUnicode
    000000000043f410 000007fef80f71ca clr!operator delete[]+0x3b, calling clr!EEHeapFreeInProcessHeap
    000000000043f420 000007fef8136479 clr!ManagedDebuggingAssistants::IsManagedDebuggerAttached+0x9, calling clr!CORDebuggerAttached
    000000000043f440 000007fef8213902 clr!AssemblySecurityDescriptor::SetEvidenceFromPEFile+0x72, calling clr!SecurityDescriptor::SetEvidence
    000000000043f450 000007fef81ee172 clr!AppDomain::SetFriendlyName+0xab, calling clr!SBuffer::~SBuffer
    000000000043f490 000007fef80f6a72 clr!GCHolder<0,0,0>::GCHolder<0,0,0>+0x33, calling clr!Thread::EnablePreemptiveGC
    000000000043f4c0 000007fef82130be clr!SystemDomain::ExecuteMainMethod+0x452, calling clr!Assembly::ExecuteMainMethod
    000000000043f650 000007fef82f450d clr!FieldDesc::GetStaticAddress+0xe, calling clr!FieldDesc::GetStaticAddressHandle
    000000000043f670 000007fef81ab75f clr!DomainLocalModule::SetClassFlags+0xcb, calling clr!CrstBase::Leave
    000000000043f6c0 000007fef80f694b clr!GCHolder<1,0,0>::~GCHolder<1,0,0>+0x2c, calling clr!Thread::EnablePreemptiveGC
    000000000043f6f0 000007fef81fcb97 clr!AppDomain::SetupSharedStatics+0xc7, calling clr!GCHolder<1,0,0>::~GCHolder<1,0,0>
    000000000043f760 000007fef80fcf76 clr!Binder::FetchMethod+0x66, calling clr!HardCodedMetaSig::GetBinarySig
    000000000043f790 000007fef80fd0ed clr!Binder::GetMethod+0x3e, calling clr!Binder::FetchMethod
    000000000043f7d0 000007fef81fcac5 clr!AppDomain::LoadSystemAssemblies+0x25, calling clr!AppDomain::LoadDomainAssembly
    000000000043f7e0 000007fef82171bd clr!SafeHandle::Init+0x2d, calling clr!Binder::GetMethod
    000000000043f810 000007fef82165c8 clr!EEStartupHelper+0x7c8, calling clr!Volatile<unsigned long>::operator!
    000000000043f870 000007fef8032113 MSVCR100_CLR0400!getptd+0xb, calling MSVCR100_CLR0400!getptd_noexit
    000000000043f8a0 000007feecc77e5f AcXtrnal+0x7e5f
    000000000043f930 000007fef8223456 clr!REGUTIL::InitOptionalConfigCache+0x1a9, calling clr!_security_check_cookie
    000000000043f9e0 000007fef8293c87 clr!ClrAllocInProcessHeapBootstrap+0x33
    000000000043fa20 000007fef82f5cd6 clr!EEStartup+0x16, calling clr!EEStartupHelper
    000000000043fa40 000007fef80f4099 clr!CLRException::HandlerState::HandlerState+0xe, calling clr!GetThread
    000000000043fa70 000007fef825f5c2 clr!ExecuteEXE+0x43, calling clr!SystemDomain::ExecuteMainMethod
    000000000043fad0 000007fef825f4df clr!CorExeMainInternal+0xc4, calling clr!ExecuteEXE
    000000000043fb40 000007fef8223835 clr!CorExeMain+0x15, calling clr!CorExeMainInternal
    000000000043fb80 000007fef8ce3309 mscoreei!CorExeMain+0x41
    000000000043fbb0 000007fef8d75b21 mscoree!CorExeMain_Exported+0x57
    000000000043fbe0 00000000773df33d kernel32!BaseThreadInitThunk+0xd
    000000000043fc10 0000000077612ca1 ntdll!RtlUserThreadStart+0x1d

    !ClrStack of Main() thread while crashing.

    0:000> ~0 e !clrstack
    OS Thread Id: 0x2bf0 (0)
    Child SP         IP               Call Site
    000000000043d960 000000007762f6fa [ComPlusMethodFrameStandalone: 000000000043d960] LICCHECKLib.CheckerClass.SetLicenseLocation(System.String)
    000000000043d8c0 000007fef1465835 DomainBoundILStubClass.IL_STUB_CLRtoCOM(System.String)
    000000000043da40 000007ff00218191 Philips.PmsCT.Base.Licensing.LicenseCheck..cctor() [D:\SnapshotViews\ISP5View\PlatformInfra\Src\Base\Base\Licensing\LicenseCheck.cs @ 675]
    000000000043dfe0 000007fef81a90b4 [GCFrame: 000000000043dfe0] 
    000000000043ebb8 000007fef81a90b4 [PrestubMethodFrame: 000000000043ebb8] Philips.PmsCT.Base.Licensing.LicenseCheck.CheckOption(System.String)
    000000000043ec20 000007ff00200171 AVA.Program.Main() [D:\SnapshotViews\ISP5View\ClinicalApps\Src\AVA\AVAprep\Program.cs @ 28]
    000000000043f0a0 000007fef81a90b4 [GCFrame: 000000000043f0a0] 

    Any Idea when static constructor could crash??

    Thanks,

    Bala.


    Bala

    Friday, October 5, 2012 7:17 AM

All replies