Loader lock error

后端 未结 9 1618
孤独总比滥情好
孤独总比滥情好 2020-12-02 07:34

I am building on C++ dll, by writing code in C#.

I get an error, saying

LoaderLock was detected Message: Attempting managed execution insid

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 08:13

    I recently got this error while creating an instance of an COM-Object written in native code:

    m_ComObject = Activator.CreateInstance(Type.GetTypeFromProgID("Fancy.McDancy"));
    

    This led to the described error. A "LoaderLock was detected"-Exception was thrown.

    I overcame this error by creating the object-instance in an extra thread:

    ThreadStart threadRef = new ThreadStart(delegate { m_ComObject = Activator.CreateInstance(Type.GetTypeFromProgID("Fancy.McDancy")); });
    Thread myThread = new Thread(threadRef);
    
    myThread.Start();
    myThread.Join(); // for synchronization
    

提交回复
热议问题