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

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

问题描述

我的问题:

我有一个签名的程序集 A.dll,它的版本号为 1.0.0.0我有另一个引用 A.dll 的程序集(比如 B.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.

什么场景/条件会导致此异常?如果有人能对此提供一些见解,将不胜感激.谢谢.

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?"

如果您重新编译 A 并将其部署为部分更新(而不是完全推出应用程序),那么如果应用程序中有任何引用旧版本的内容,您的应用程序可能会崩溃,除非您仍然拥有旧版本的 A 也可用(即您没有覆盖它).

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天全站免登陆