AppDomain.Unload 不会删除 dll 上的锁定
我使用以下代码创建新的 AppDomain 并将我的程序集加载到其中,我的程序集成功加载,但在我调用 AppDomain.Unload 方法后,加载的 dll 上仍然存在锁定,我在其中创建新的 AppDomain 解决方案,因为我在网上发现这是加载/卸载组件以及使组件可替换的推荐技术,有什么想法吗?
这是我的代码:
public sealed class AssemblyLoader : MarshalByRefObject
{
private static AppDomain LocalDomain = AppDomain.CreateDomain("LocalDomain");
public static Assembly LoadAssembly(string path)
{
try
{
Assembly assembly = Assembly.Load(AssemblyName.GetAssemblyName(path));
if (assembly != null)
return assembly;
}
catch { }
return Assembly.LoadFrom(path);
}
public static void Unload()
{
if (LocalDomain != null)
{
AppDomain.Unload(LocalDomain);
LocalDomain = null;
}
}
}
am using the following code to create new AppDomain and load my assemblies into it, where my assemblies load successfully, but after i call the AppDomain.Unload method, there is still lock on the loaded dlls, where i went for creating new AppDomain solution because i found over the net that this is the recommended technique to load/unload assemblies and also to make the assemblies replaceable, any idea?
here is my code:
public sealed class AssemblyLoader : MarshalByRefObject
{
private static AppDomain LocalDomain = AppDomain.CreateDomain("LocalDomain");
public static Assembly LoadAssembly(string path)
{
try
{
Assembly assembly = Assembly.Load(AssemblyName.GetAssemblyName(path));
if (assembly != null)
return assembly;
}
catch { }
return Assembly.LoadFrom(path);
}
public static void Unload()
{
if (LocalDomain != null)
{
AppDomain.Unload(LocalDomain);
LocalDomain = null;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定,但从理论上讲,它不应该更像这样。
您没有通过新创建的 AppDomain 加载程序集。
I'm not sure but from the theory shouldn't it be more like this.
You're not loading the assembly through the newly created AppDomain.