ExecuteInDefaultAppDomain返回8013101B

时间:2012-01-25 20:11:08

标签: c#

我正在尝试在我的原生Win32 C ++应用程序中托管CLR。

CLR加载工作正常,但是当我尝试在程序集中执行一个方法时,ExecuteInDefaultAppDomain返回0x8013101B,然后退出。

以下是代码段:

// Managed Code
namespace ManagedLibrary
{
    public class LibraryBootstrapper
    {
        static LibraryBootstrapper()
        {
            MessageBox.Show("Static LibraryBootsrapper");
        }

        public LibraryBootstrapper()
        {
        }

        public static int Initialize(String str)
        {
            MessageBox.Show("Hi " + str + ", Library Bootsrapped");

            return 0;
        }
    }


// Native Code
int tmain()
{
    // Bind to the runtime.
    ICLRRuntimeHost *pClrHost = NULL;
    HRESULT hrCorBind = CorBindToRuntimeEx(
        NULL,   // Load the latest CLR version available
        L"wks", // Workstation GC ("wks" or "svr" overrides)
        0,      // No flags needed
        CLSID_CLRRuntimeHost,
        IID_ICLRRuntimeHost,
        (PVOID*)&pClrHost);


    // Now, start the CLR.
    HRESULT hrStart = pClrHost->Start();

    DWORD result = 0;

    // Load an assembly and execute a method in it.
    HRESULT hrExecute = pClrHost->ExecuteInDefaultAppDomain(L"C:\\KIRAN\\Workspaces\\VS 2010\\HostCLR\\ManagedLibrary\\bin\\Debug\\ManagedLibrary.dll", L"ManagedLibrary.LibraryBootstrapper", L"Initialize", L"Kiran", &result);

    //HRESULT hrStop = pClrHost->Stop();

    return;
}

2 个答案:

答案 0 :(得分:3)

我明白了!

问题在于本机和托管项目引用的.NET框架版本不同。同步起来有效。

而且,顺便说一下,错误代码0x8013101B对应于COR_E_NEWER_RUNTIME(参见corerror.h),这有助于我找出问题所在。

答案 1 :(得分:1)