装配在同一项目中的C#加载不同版本 [英] C# Load different versions of assembly to the same project

查看:175
本文介绍了装配在同一项目中的C#加载不同版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造了一些工具进行什么样NUnit的几个操作。 在这个工具,我打开.dll文件汇编和调用方法形成它来运行一些测试。

I'm creating some tool what performs several operations like NUnit. Inside this tool I open .dll assembly and invoke methods form it to run some test.

一切都很OK,直到我需要重新加载的.dll全无程序重新启动的时间。该思想是,当工具运行我们所需的组件复制到一些临时文件夹,并从那里调用。如果我需要重新加载我复制一份到另一个临时文件夹,并尝试加载从另一个文件夹中新复制并加载到previous装配对象

Everything is going OK till the time I need to reload .dll withour program restart. The idea is that when tool is run we copy required assembly to some temporary folder and invoke from there. If I need to reload I copy another one to another temporary folder and try to load newly copied from another folder and load to previous assembly object

  ExecutingAssembly = Assembly.LoadFrom(AssemblyFullPath); 

但我的问题是,当我改变AssemblyFullPath为新的,并调用Assembly.LoadFrom返回只是旧组件发生了什么加载第一次,但没有第二个! 也许问题是,我们不能加载多个程序集的不同版本?有什么解决办法?

But my problem is that after I change AssemblyFullPath to new one and call Assembly.LoadFrom it returns just old assembly what was loaded first time but not the second one! Maybe the problem is that we cannot load several assemblies with different versions? What is the solution?

推荐答案

在CLR确实支持加载多个版本的强命名程序集到相同的的AppDomain 。这只但如果你的程序集强命名的,每个人都有不同的版本比其他。

The CLR does support loading multiple versions of strongly named assemblies into the same AppDomain. This only works though if your assemblies are strongly named and each one has a different version than the other.

我猜它更可能是你正在处理未签名的程序集。如果这是你问那么什么情况下是不是真的有可能。一旦给定的组件加载到一个的AppDomain 将保留在那里,直到的AppDomain 卸载。为了得到这个工作,你将不得不抽象出周围所有的加载的程序集的工作到一个单独的的AppDomain 并使用新的的AppDomain 为每个组件

I'm guessing it's more likely that you are dealing with unsigned assemblies. If that is the case then what you're asking for isn't really possible. Once a given assembly is loaded into an AppDomain it will remain there until the AppDomain is unloaded. To get this to work you will have to abstract out all of the work around the loaded assemblies into a separate AppDomain and use a new AppDomain for every assembly

这篇关于装配在同一项目中的C#加载不同版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆