[英]Assembly.LoadFrom load wrong assembly
I'm using Assembly.LoadFrom to load my dll and create an instance of it later. 我正在使用Assembly.LoadFrom加载我的dll,并在以后创建它的实例。
Here is my problem. 这是我的问题。 Sometime I can modify my dll.
有时我可以修改我的dll。 More precisely I delete it and create a new one with the same name and path.
更确切地说,我将其删除并使用相同的名称和路径创建一个新的。 And when I instantiate it again and call methods I see that the instance being used is the first one.
当我再次实例化它并调用方法时,我看到正在使用的实例是第一个。
If I close my application and call my method the good instance is being used. 如果我关闭我的应用程序并调用我的方法,那么将使用好的实例。
So is there a way to deallocate resources or free the instance ? 那么有没有办法释放资源或释放实例? Here is my sample code
这是我的示例代码
Assembly sampleAssembly = Assembly.LoadFrom(pathToDll);
MyClassEntity = sampleAssembly.CreateInstance("InstanceName") as MyClass;
MyClass is an abstract class. MyClass是一个抽象类。
Assemblies are loaded once and kept in memory. 程序集被加载一次并保存在内存中。 You'd have to load it into a separate
AppDomain
and rid the domain to rid the loaded assembly. 您必须将其加载到单独的
AppDomain
并删除域以摆脱已加载的程序集。
See this link: http://msdn.microsoft.com/en-us/library/vstudio/ms173101.aspx 请参阅此链接: http : //msdn.microsoft.com/en-us/library/vstudio/ms173101.aspx
And this: How to reload an assembly for a .NET Application Domain? 并且: 如何为.NET应用程序域重新加载程序集?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.