我在 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/