C# 错误:需要强命名程序集
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/290980/
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
Error: A strongly-named assembly is required
提问by Yaakov Ellis
I have a Windows forms project (VS 2005, .net 2.0). The solution has references to 9 projects. Everything works and compiles fine on one of my computers. When I move it to a second computer, 8 out of the 9 project compile with no problem. When I try to compile the 9th project (the main project for the application - produces the .exe file to execute the application), I get the following error:
我有一个 Windows 窗体项目(VS 2005,.net 2.0)。该解决方案引用了 9 个项目。在我的其中一台计算机上一切正常并且编译良好。当我将它移动到第二台计算机时,9 个项目中有 8 个编译没有问题。当我尝试编译第 9 个项目(应用程序的主项目 - 生成 .exe 文件来执行应用程序)时,出现以下错误:
'Error 3: A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)'
The file location for the error is is listed as "C:\PATH-TO-APP\LC".
错误的文件位置列为“C:\PATH-TO-APP\LC”。
I have checked in the project properties and all of the projects are set to build in Debug mode, none of them are supposed to be signed. In the project that is failing, the only assembly that it references that is not in any of the other projects is Microsoft.VisualBasic (a .net 2.0 assembly). So I am at a loss to find what ids causing this error (the file referenced above in the error message - "LC" - does not exist.
我已经检查了项目属性,并且所有项目都设置为在调试模式下构建,它们都不应该被签名。在失败的项目中,它引用的唯一一个不在任何其他项目中的程序集是 Microsoft.VisualBasic(一个 .net 2.0 程序集)。因此,我无法找到导致此错误的 ID(上面错误消息中引用的文件 - “LC” - 不存在。
Anyone know how I can force the project to accept all unsigned assemblies, or to determine which assembly is the culprit?
任何人都知道我如何强制项目接受所有未签名的程序集,或者确定哪个程序集是罪魁祸首?
The only meaningful difference between the dev environments between the dev environment where this worked and the current one is that the first was XP and this is Vista64. However, a colleague of mine who is using XP is getting the same error.
开发环境与当前开发环境之间唯一有意义的区别是第一个是 XP,这是 Vista64。但是,我的一位使用 XP 的同事也遇到了同样的错误。
Third-party assemblies being used:
正在使用的第三方程序集:
- ComponentFactory.Krypton.Toolkit
- ComponentFactory.Krypton.Navigator
- VistaDB.NET20
- ComponentFactory.Krypton.Toolkit
- ComponentFactory.Krypton.Navigator
- VistaDB.NET20
All of these are referenced in other projects in the solution which build with no problems, so it doesn't look like these are the problem.
所有这些都在解决方案中的其他项目中被引用,这些项目没有问题,所以看起来这些不是问题。
So far I have tried deleting the suo file, Rebuild All, unloading and reloading projects from the solution, removing and readding referenced assemblies. Nothing has worked.
到目前为止,我已经尝试删除 suo 文件,重建全部,从解决方案中卸载和重新加载项目,删除和读取引用的程序集。没有任何效果。
采纳答案by Yaakov Ellis
I just got it to build by doing the following:
我只是通过执行以下操作来构建它:
There had been a licenses file in the Properties of the project in question. After deleting the file (it was no longer needed) the project was able to build successfully. So it looks like that was the culprit.
相关项目的属性中有一个许可证文件。删除文件(不再需要)后,项目能够成功构建。所以看起来这就是罪魁祸首。
回答by Charles Bretana
Check the references section of each project in the solutions explorer... Look for references to third party vendor assemblys Like Infragistics, or Data Dynamics, etc. that might not be installed on the machine where you are experiencing the issue
检查解决方案资源管理器中每个项目的参考部分...查找对第三方供应商程序集(如 Infragistics 或 Data Dynamics 等)的引用,这些程序集可能未安装在您遇到问题的机器上
回答by Charles Bretana
ok, not sure if this will help, but if you have access to ildasm, examine the three third party assemblies and check the following: (I found the following googling on your error msg) Its from another guys post, so ignore the names, but the key is that inside the manifest the line should read ".publickeytoken" not ".publickey" Link to this thread is at:
好的,不确定这是否有帮助,但是如果您可以访问 ildasm,请检查三个第三方程序集并检查以下内容:(我在您的错误消息中发现了以下谷歌搜索)它来自另一个人的帖子,所以忽略名称,但关键是,在清单中,该行应为“.publickeytoken”而不是“.publickey”,该线程的链接位于:
http://social.msdn.microsoft.com/Forums/en-US/clr/thread/56e13ab1-4c03-4571-92f1-759081bcc78b/
http://social.msdn.microsoft.com/Forums/en-US/clr/thread/56e13ab1-4c03-4571-92f1-759081bcc78b/
Public Key or Token: ab 1a 81 37 f9 79 0c 88
Loooks ok, right? That sequence really is the public key token of Reflex.dll.
看起来还行吧?该序列确实是 Reflex.dll 的公钥标记。
The problem can be seen if we use the ildasm gui and click on "manifest":
如果我们使用 ildasm gui 并单击“manifest”,则可以看到问题:
.assembly extern Reflex
{
.publickey = (2F 5A 20 3A 86 D3 5F 71 ) // /Z :.._q
.ver 1:0:0:0
}
Notice the .publickey line.
注意 .publickey 行。
It should say .publickeytoken!!!
它应该说.publickeytoken!!!
The problem is that the Cecil module, when creating the modified assembly, puts the public key token in the public key field (or forgets to turn on some flag that says that thiss is a token, not a complete public key. I'm unaware of the details).
问题是 Cecil 模块在创建修改后的程序集时,将公钥令牌放在公钥字段中(或者忘记打开一些标志,表明这是一个令牌,而不是一个完整的公钥。我不知道的细节)。
So this amounts to a probable bug in Cecil...I should have used Gael's thing instead.... :)
所以这相当于 Cecil 中的一个可能的错误......我应该使用 Gael 的东西...... :)
anyway, now I know that the ONLY problem with the original script (before I moved to Cecil) was that it was putting a reference to a non-strongly-named assembly (Reflex) inside a strongly-named assembly (FXCOP).
无论如何,现在我知道原始脚本的唯一问题(在我搬到 Cecil 之前)是它在强命名程序集 (FXCOP) 中放置了对非强命名程序集 (Reflex) 的引用。
So I fixed that now and re-ran my original script and...viola! It works!!
所以我现在解决了这个问题并重新运行了我的原始脚本和......中提琴!有用!!
回答by Dirk Vollmar
It could be that you have to specify your target platform explicitly and set it to x86. There might be an issue with the 64bit build.
可能是您必须明确指定目标平台并将其设置为 x86。64 位版本可能存在问题。
Another thing: Do you run VS as Administrator? There are issues with VS2005 when it is not running with elevation on Vista, maybe this strange compile error is one of them.
另一件事:您是否以管理员身份运行 VS?VS2005 在 Vista 上没有以提升运行时会出现问题,也许这个奇怪的编译错误就是其中之一。
回答by Alex
I had been using many third-party libraries (MS Ent Lib) and decided to move a few of the dll's to an 'unused' folder. This gave me the error in question. I believe one of the libraries I referenced actually references another library that needs to sit alongside it (even though the dll does not need to be referenced in your project).
我一直在使用许多第三方库(MS Ent Lib)并决定将一些 dll 移动到“未使用”文件夹中。这给了我有问题的错误。我相信我引用的其中一个库实际上引用了另一个需要与它并排放置的库(即使不需要在您的项目中引用 dll)。
After moving the libraries back everything compiled without this error.
将库移回后,所有编译的内容都没有出现此错误。
回答by Youssef Salame
I've removed the license file from My Project Folder, and re-build again, it was build successfully.
我已经从我的项目文件夹中删除了许可证文件,并再次重新构建,它已成功构建。
回答by miroxlav
Yet another possible cause:
还有一个可能的原因:
(for desperate troubleshooters)
(对于绝望的故障排除者)
In Solution Explorerwindow, if you walk down your references list and check each in Propertieswindow, seeing property Strong Name = Falsepoints to potential problem.
在“解决方案资源管理器”窗口中,如果您向下浏览引用列表并在“属性”窗口中检查每一个,看到属性Strong Name = False表示潜在问题。
回答by 落魄山
A strange fix for me, but I had just pulled this solution from source control.
对我来说这是一个奇怪的修复,但我刚刚从源代码管理中提取了这个解决方案。
Was getting this error, went through most of the answers above, and then deleted the solution and re-pulled the solution from source control.
收到此错误,浏览了上面的大部分答案,然后删除了解决方案并从源代码管理中重新提取了解决方案。
Worked.
工作了。
Will only apply to a few, but I guess I was one of the few so there will be more. Not sure what happened the first time, but somehow some assemblies must have had some issues when I pulled them across.
只适用于少数人,但我想我是少数人之一,所以会有更多。不确定第一次发生了什么,但不知何故,当我将它们拉过来时,某些程序集一定有一些问题。
Essentially turn it off and on again.
基本上将其关闭并再次打开。