C# ExecuteInDefaultAppDomain返回801310B 我试图在我的本地Win32 C++应用程序中提供CLR。

C# ExecuteInDefaultAppDomain返回801310B 我试图在我的本地Win32 C++应用程序中提供CLR。,c#,C#,CLR加载工作正常,但当我尝试在程序集中执行方法时,ExecuteInDefaultAppDomain返回0x80131B,然后退出 以下是代码片段: // Managed Code namespace ManagedLibrary { public class LibraryBootstrapper { static LibraryBootstrapper() { MessageBox.Show("Static Libra

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

以下是代码片段:

// 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;
}
我知道了

问题在于本机项目和托管项目引用的.NET Framework版本不同。同步成功了


顺便说一句,错误代码0x801310B对应于COR_E_NEWER_运行时(请参阅corerror.h),这帮助我解决了问题。

这里解释了错误代码: