大会的版本号,签名的程序集为什么我得到一个FileLoadExceptions [英] Assembly Version numbers, signed assemblies Why do I get a FileLoadExceptions

查看:198
本文介绍了大会的版本号,签名的程序集为什么我得到一个FileLoadExceptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:

我有一个签名的程序集A.DLL其版本为1.0.0.0 我还有一个程序集(可以说B.DLL)引用A.DLL。

I have a signed assembly A.dll that it versioned as 1.0.0.0 I have another assembly (lets say B.dll) that references A.dll.

在这两个组件两个组件加载罚款没有任何问题。 现在,如果版本A.DLL更改为1.0.0.1,并重新编译确实B.DLL必须重新编译?

Once both assemblies both assemblies load fine without any problem. Now if the version for A.dll changes to 1.0.0.1 and is recompiled Does B.dll have to be recompiled?

我问,因为我已经在那里后A.DLL有它的版本改变了我现在收到以下异常试图加载B.DLL这个确切的方案:

I asking because I have this exact scenario where after A.dll had it's version changed I now receive the following Exception trying to load B.dll:

Unhandled Exception: System.IO.FileLoadException: 
    Could not load file or assembly A, Version=1.0.0.0, 
    Culture=neutral, PublicKeyToken…

这让我觉得这个问题的答案是肯定的始终。不过我还有一个例子,我有两个组件具有上述的确切的情况,我没有任何问题,加载的程序集。

This makes me think that the answer to this question is always yes. However I have another example where I have two assemblies that have the exact scenario described above and I do not have any problem loading the assemblies.

什么情况下/条件导致此异常?如果任何人都可以提供一些洞察到这一点,将是极大的AP preciated。 谢谢你。

What scenario/conditions cause this exception? If anyone can offer some insight to this it would be greatly appreciated. Thanks.

推荐答案

当一个程序集强命名,任何引用它会寻找特定版本。

When an assembly is strongly named, anything that references it will look for that specific version.

您是正确的,在Visual Studio中特定版本犯规影响以任何方式运行。事实上,在特定版本基本上意味着当你运行构建,如果MSBUILD无法找到被引用的版本,应该构建失败,或者只是使用,可以在文件系统中找到的下一个版本?

You are correct that 'Specific Version' in Visual Studio doesnt affect the runtime in any way. In fact, the 'Specific Version' basically means "When you run a build, if MSBUILD cannot find the version that was referenced, should the build fail, or just use the next version that can be found on the filesystem?"

如果你重新编译和部署,作为一个部分更新(而不是完全推出的应用程序),那么如果在引用旧版本的应用程序什么,你的应用程序可能会中断,除非你仍然有旧版本可用,以及(即你没有覆盖它)。

If you recompile A, and deploy it, as a partial update (rather than fully rolling out the application), then if there is anything in the application that references the old version, your application may break, unless you still have the old version of A available as well (i.e. you didnt overwrite it).

这是一个最主要的原因,部分产品使用GAC,因为它可以保存多个版本的同一个DLL中,而不会覆盖对方 - 如果你尝试不同版本的同一文件部署到您的bin文件夹(假设他们有相同的文件名,他们通常做的),他们会互相覆盖,而你只结束了1你的产品的DLL!

This is a main reason why some products use the GAC, because it can hold multiple versions of the same DLL without overwriting each other - if you tried to deploy different versions of the same file into your bin folder (assuming they had the same file name, which they typically do), they would overwrite each other, and you'd only end up with 1 of the DLLs in your product!

还有一个窍门,你可以做的就是把你的再版本的DLL中的子文件夹,然后二进制目录下,并修改的app.config告诉运行时在哪里可以找到他们。 http://support.microsoft.com/kb/837908

Another trick you can do is put your 're-versioned' DLLs in a sub-folder under then binary directory, and edit the app.config to tell the runtime where to find them. http://support.microsoft.com/kb/837908

所以,总结一下,一个强命名程序集使用不仅仅是简单的名称来确定程序集的标识 - 改变其形式可以认为是彻底改变它的名字

So, to sum up, a strongly named assembly uses more than just the simple name to determine an assembly's identity - changing its version could be thought of as changing its name completely.

这篇关于大会的版本号,签名的程序集为什么我得到一个FileLoadExceptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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