.net 无法加载文件或程序集“AssemblyName PublicKeyToken=null”或其依赖项之一
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21435283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not load file or assembly 'AssemblyName PublicKeyToken=null' or one of its dependencies
提问by Pantelis
{"Could not load file or assembly 'AssemblyName, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"AssemblyName, PublicKeyToken=null"}
{“无法加载文件或程序集‘AssemblyName,PublicKeyToken=null’或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)”:“AssemblyName,PublicKeyToken=null”}
I'm getting the message in question as an InnerException.Messagewhile trying to debug my application after signing the unsigned third-party assemblies it is using.
The weird thing is that I have already signed the assembly shown in the message, the one that can't be loaded.
在对InnerException.Message我的应用程序使用的未签名第三方程序集进行签名后尝试调试我的应用程序时,我收到了有问题的消息。奇怪的是,我已经签署了消息中显示的程序集,无法加载的程序集。
What could the problem be here? How can I resolve this?
这里可能有什么问题?我该如何解决这个问题?
EDIT
编辑
Editing to give more information on what I did:
编辑以提供有关我所做工作的更多信息:
- Signed all the unsigned third-party assemblies my project is referencing.
- Disassembled those assemblies to see if they internally reference any external unsigned assemblies (they didn't)
- Deleted the old unsigned assemblies from the project's reference list, and re-added the newly signed ones.
- Unloaded the project and edited the reference of the assembly that can't be loaded in the .sln XML-styled file by adding the PublicKeyToken that was missing from the assembly reference.
- 签署了我的项目引用的所有未签名的第三方程序集。
- 反汇编这些程序集以查看它们是否在内部引用了任何外部未签名的程序集(它们没有)
- 从项目的参考列表中删除了旧的未签名程序集,并重新添加了新签名的程序集。
- 卸载项目并通过添加程序集引用中缺少的 PublicKeyToken 编辑无法在 .sln XML 样式文件中加载的程序集引用。
The assembly that throws the exception, btw the project builds fine it's a runtime exception I'm getting on InitializeComponent()of that assembly, is an open source component with WPF controls (MahApps.Metro). I've found a similar question but none of the answers there fixed the issue.
引发异常的程序集,顺便说一句,项目构建良好,这是我正在处理InitializeComponent()的该程序集的运行时异常,是一个带有 WPF 控件(MahApps.Metro)的开源组件。我发现了一个类似的问题,但那里的答案都没有解决这个问题。
How to force WPF to use resource URIs that use assembly strong name? Argh!
回答by Hans Passant
PublicKeyToken = null tells you that the CLR is looking for the unsignedassembly. Since you signed them, that's not going to work well and this kaboom is expected.
PublicKeyToken = null 告诉您 CLR 正在寻找未签名的程序集。既然你签了他们,这不会很好地工作,而且这个 kaboom 是预期的。
You will have to rebuildthe program so it uses the updated signed assembly and embeds the non-null PublicKeyToken into the manifest. You may have to remove the existing assembly reference and add it back, it isn't clear from the question whether you built the program using an unsigned copy.
您必须重建程序,以便它使用更新的签名程序集并将非空 PublicKeyToken 嵌入到清单中。您可能必须删除现有的程序集引用并将其添加回来,从问题中不清楚您是否使用未签名的副本构建程序。
Use the Fuslogvw.exe utility if you still have trouble.
如果仍有问题,请使用 Fuslogvw.exe 实用程序。
回答by habakuk
Maybe one of your "unsigned third-party assemblies" has a reference to another one of your "unsigned third-party assemblies" - so the reference is wrong after you signed them all.
也许您的一个“未签名的第三方程序集”引用了另一个“未签名的第三方程序集”-因此在您对它们全部签名后,该引用是错误的。
Maybe this tool can help you: https://github.com/brutaldev/StrongNameSigner- it can update the assemblies (it probably also can done by using the command line, but I don't know how).
也许这个工具可以帮助你:https: //github.com/brutaldev/StrongNameSigner- 它可以更新程序集(它可能也可以通过使用命令行来完成,但我不知道如何)。
回答by tomt
- backup all the production dll and files to another folder - just in case to rollback
- copy all the production dlls that the current process is running to your local project
- reference all these dlls on all the related local projects.
- Compile and copy the project dlls out again to try starting the window services.
- 将所有生产 dll 和文件备份到另一个文件夹 - 以防万一回滚
- 将当前进程正在运行的所有生产 dll 复制到您的本地项目
- 在所有相关的本地项目上引用所有这些 dll。
- 再次编译并复制项目 dll 以尝试启动窗口服务。
still not working yet.
还没有工作。
- backup all the production dll and files to another folder - just in case to rollback
- Copy all the new compiled dlls from the local projects and over-ride the dlls to the production folder
- start up the window service
- 将所有生产 dll 和文件备份到另一个文件夹 - 以防万一回滚
- 从本地项目复制所有新编译的 dll 并将这些 dll 覆盖到生产文件夹
- 启动窗口服务
回答by Ed Ajaz
I noticed you did say you signed the 3rd party libraries, but don't forget to also sign your own assemblies that use the 3rd party libs as well. Most importantly would be the assembly using the signed libs. This was how I recently fixed this issue for myself.
我注意到你确实说过你签署了 3rd 方库,但不要忘记也签署你自己的使用 3rd 方库的程序集。最重要的是使用签名库的程序集。这就是我最近为自己解决这个问题的方式。
Visual studio is sometimes overly forgiving and allows us to get away with more than we should. Other times? Not so much.
Visual Studio 有时过于宽容,让我们可以逃脱超出应有的范围。其他时间?没那么多。
Be sure to clean your project after making the changes as well. Then rebuild the solution. Hopefully that will get you a step further.
在进行更改后,请务必清理您的项目。然后重建解决方案。希望这会让你更进一步。

