[英]C# can't find assembly which is already loaded
I am writing an application which uses plugins. 我正在编写一个使用插件的应用程序。 Plugins are class libraries which lie in Plug-ins directory.
插件是位于插件目录中的类库。 My app loads these libraries via LoadFrom.
我的应用程序通过LoadFrom加载这些库。 Some of them have dependencies in the form of libraries which lie in the same Plug-ins directory.
其中一些具有库的形式的依赖关系,它们位于相同的插件目录中。 When I try to create instance of class from one of plugins via Activator.CreateInstance i recieve an exception 'Unable to find assembly' (this is dependency assembly of plugin), but this assembly is already loaded (!) along with plugins and It is visible in ProcessExplorer.
当我尝试通过Activator.CreateInstance从其中一个插件创建类的实例时,我收到一个异常'无法找到程序集'(这是插件的依赖程序集),但是这个程序集已经加载(!)和插件,它是在ProcessExplorer中可见。 I can't uderstand in what my trouble is.
我无法理解我的麻烦。
Your problem might be, that de loaded assembly isn't the same version as the request one. 您的问题可能是,de加载的程序集与请求程序集的版本不同 。 .Net Runtime maps the Assembly after their name and after their Version if the name equals and the Version differes you get an exception if the other one is loaded, which says "Assembly cann't be found" or something like that.
.Net运行时将程序集在它们的名称之后和它们的版本之后映射,如果名称等于,并且版本差异,如果加载了另一个,则会得到异常,即“无法找到程序集”或类似的东西。 The Problem is, that the assembly could not be matched properly.
问题是,组件无法正确匹配。 But there is a solution:
但有一个解决方案:
Take a look at the MSDN for further information about that Problem. 请查看MSDN以获取有关该问题的更多信息。
I recommend implementing the event anyways if you deal with plugins, so you can log all assembly requests of that AppDomain.
如果您处理插件,我建议无论如何都要实现该事件,以便您可以记录该AppDomain的所有程序集请求。
You will find furhter information about runtime behavior and assembly loading here 您将在此处找到有关运行时行为和程序集加载的更多信息
Hope i could help, please give us feedback about your solution! 希望我能提供帮助,请向我们提供有关您解决方案的反馈!
You should provide Full Path of assembly files. 您应该提供程序集文件的完整路径。
class Program
{
static void Main(string[] args)
{
var asmFileName = "test.dll"; // Your plug-in file name
var asmPath = AppDomain.CurrentDomain.BaseDirectory; // Your assemblies's root folder
var asmFullPath = System.IO.Path.Combine(asmPath, asmFileName);
var asm = System.Reflection.Assembly.LoadFrom(asmFullPath);
}
}
我有类似的问题,他们通常通过改变项目属性中的目标框架来解决...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.