gpt4 book ai didi

c# - ExecuteInDefaultAppDomain 返回 8013101B

转载 作者:太空狗 更新时间:2023-10-30 01:24:32 27 4
gpt4 key购买 nike

我正在尝试在我的 native 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;
}

最佳答案

我想通了!

问题是 native 项目和托管项目引用的 .NET 框架版本不同。同步成功。

顺便说一句,错误代码 0x8013101B 对应于 COR_E_NEWER_RUNTIME(请参阅 corerror.h),这帮助我找出了问题。

关于c# - ExecuteInDefaultAppDomain 返回 8013101B,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9009569/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com