gpt4 book ai didi

c++ - 如何释放在 C++ 中加载的 DotNet 程序集

转载 作者:行者123 更新时间:2023-11-28 07:51:06 25 4
gpt4 key购买 nike

我在 C++ DLL 中有以下代码。它在使用 C# 构建的 DotNet DLL 中加载和调用方法。

Assembly^ a = Assembly::LoadFrom(gcnew String("MyDotNet.dll"));
Type^ type = a->GetType("MyAssemply.Assembly");
MethodInfo^ method = type->GetMethod("MyMethod");
Object^ obj = Activator::CreateInstance(type);
array<Object^>^ params = gcnew array<Object^>(0) { };
Object^ ret = method->Invoke(obj, params);

问题是,即使我在 C++ DLL 上执行 FreeLibrary,它似乎也没有释放资源或 DLL。是否需要调用 API 或方法来释放 DLL/资源?

我正在使用 Visual Studio 2010。

谢谢。

最佳答案

您不能从应用程序池中卸载托管程序集。您可以创建另一个应用程序池并卸载它。

这篇文章是相关的:How to unload an assembly from the primary AppDomain?

关于c++ - 如何释放在 C++ 中加载的 DotNet 程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13766400/

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