C# 强名称验证失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/403731/
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
Strong Name Validation Failed
提问by
Two machines. Both with .NET 3.5 and the VS 2008 VC++ SP1 redistributables
两台机器。.NET 3.5 和 VS 2008 VC++ SP1 可再发行组件
A single exe which uses two signed DLLs, one in C++/CLI and one in C#
一个使用两个签名 DLL 的单个 exe,一个在 C++/CLI 中,一个在 C# 中
The exe loads and runs fine on one machine.
exe 加载并在一台机器上运行良好。
On the other, I get "Strong Name Validation Failed" on the C++ executable (HRESULT 0x8013141A)
另一方面,我在 C++ 可执行文件(HRESULT 0x8013141A)上得到“强名称验证失败”
Any ideas?
有任何想法吗?
回答by Colin Desmond
Is the one the code runs on a "development" machine where you might have run "sn.exe -Vr AssemblyName.dll" at some stage which would allow you to use a delay signed assembly as if it were fully signed. When you transfer the delay signed assembly to another machine and run it, it will fail strong name validation because it is not fully signed.
代码是在“开发”机器上运行的,您可能在某个阶段运行了“sn.exe -Vr AssemblyName.dll”,这将允许您使用延迟签名的程序集,就好像它是完全签名的一样。当您将延迟签名的程序集传输到另一台机器并运行它时,它会因为没有完全签名而无法通过强名称验证。
回答by Richard Anthony Hein
You must use the 64-bit version of sn.exe on a 64-bit machine. (C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sn.exe)
您必须在 64 位计算机上使用 64 位版本的 sn.exe。(C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sn.exe)
回答by Adam Szabo
Open the command prompt as administratorand enter the following command:
以管理员身份打开命令提示符并输入以下命令:
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sn.exe" -Vr <dllpath>
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sn.exe" -Vr <dllpath>
Pay attention that the argument are case sensitive. Source with more details: http://blogs.msdn.com/b/keithmg/archive/2012/03/20/strong-name-validation-failed-exception-from-hresult-0x8013141a.aspx
注意参数区分大小写。更多详细信息来源:http: //blogs.msdn.com/b/keithmg/archive/2012/03/20/strong-name-validation-failed-exception-from-hresult-0x8013141a.aspx
回答by jocull
You might be able to bypass this on development by going into the project settings -> Signing -> and unchecking "Sign the assembly".
您可以通过进入项目设置 -> 签名 -> 并取消选中“签署程序集”来绕过开发过程。
I ran into this today while debugging against a source code copy of the Entity Framework.
我今天在调试实体框架的源代码副本时遇到了这个问题。
回答by jo.p.kennedy
I encountered this today and stumbled across http://timgeerts.blogspot.co.uk/2009/08/strong-name-validation-failed.html, which seems to be the solution.
我今天遇到了这个问题,偶然发现了http://timgeerts.blogspot.co.uk/2009/08/strong-name-validation-failed.html,这似乎是解决方案。
Option 1) Turn off code coverage (in VS 2010, go to Test Settings -? Data and Diagnostics -? Untick the "Enabled" box next to Code Coverage).
选项 1) 关闭代码覆盖率(在 VS 2010 中,转到测试设置 -?数据和诊断 -?取消选中代码覆盖率旁边的“已启用”框)。
Option 2) Add the signing key file to the code coverage configuration (in VS 2010, go to Test Settings -? Data and Diagnostics -? select Code Coverage and click on "Configure" at the top. This corresponds to the "keyFile" attribute for the CodeCoverage tag in the .testsettings file.)
选项 2) 将签名密钥文件添加到代码覆盖率配置中(在 VS 2010 中,转到 Test Settings -? Data and Diagnostics -? 选择 Code Coverage 并单击顶部的“Configure”。这对应于“keyFile”属性对于 .testsettings 文件中的 CodeCoverage 标记。)
In VS 2012, code coverage is enabled by default. It can be disabled through a .runsettings file with an appropriate exclusion. See http://msdn.microsoft.com/en-us/library/jj159530.aspxfor more information and a sample file. For option 2, although there doesn't seem to be an explicit setting available in the .runsettings file, the right thing seems to happen automatically with regard to signing (YMMV). However, if you're referencing a VS 2010 .testsettings file then it will need editing as above.
在 VS 2012 中,默认情况下启用代码覆盖。可以通过具有适当排除项的 .runsettings 文件禁用它。有关详细信息和示例文件,请参阅http://msdn.microsoft.com/en-us/library/jj159530.aspx。对于选项 2,虽然 .runsettings 文件中似乎没有可用的显式设置,但在签名 (YMMV) 方面似乎会自动发生正确的事情。但是,如果您引用的是 VS 2010 .testsettings 文件,则需要按上述方式进行编辑。
回答by Fery
I am working with VS.Net Ultimate 2012
我正在使用 VS.Net Ultimate 2012
and this solution helped me:
这个解决方案帮助了我:
Right click on Project-> properties-> Build Tab-> switch Generate serialization assembly to off-> done
右键单击项目-> 属性-> 构建选项卡-> 将生成序列化程序集切换为关闭-> 完成
回答by Vishnu Prasanth
The SN.EXE is Missing in Newer versions of Visual Studio. In Visual studio 2012, we must use "Developer command prompt for Visual studio 2012". Then Run the command "sn".
较新版本的 Visual Studio 中缺少 SN.EXE。在 Visual Studio 2012 中,我们必须使用“Visual Studio 2012 的开发人员命令提示符”。然后运行命令“sn”。
Syntax: sn -Vr *,2d58152b8e842be2
语法:sn -Vr *,2d58152b8e842be2
where "2d58152b8e842be2" is the public key token shown in the Error message. Somehow this alone did not solve my problem.
其中“2d58152b8e842be2”是错误消息中显示的公钥令牌。不知何故,仅此一项并不能解决我的问题。
回答by Butsaty
Open the command prompt as administrator and enter following commands:
以管理员身份打开命令提示符并输入以下命令:
reg DELETE "HKLM\Software\Microsoft\StrongName\Verification" /f
reg ADD "HKLM\Software\Microsoft\StrongName\Verification\*,*" /f
reg DELETE "HKLM\Software\Wow6432Node\Microsoft\StrongName\Verification" /f
reg ADD "HKLM\Software\Wow6432Node\Microsoft\StrongName\Verification\*,*" /f
回答by christiansr85
In my case, I had the same issue with Visual Studio 2015
and I already had signed the assembly.
就我而言,我遇到了同样的问题,Visual Studio 2015
并且我已经签署了程序集。
I fixed it by this way: Right click on the project which causes the issue -> "Properties" -> "Build" -> Change the value of the "Platform target" field.
我通过这种方式修复了它:右键单击导致问题的项目->“属性”->“构建”->更改“平台目标”字段的值。
I had to change it from Any CPU
to x86
but I guess that in function of the project and the library which is failing, you should change its value to x64
.
我不得不将它从 to 更改Any CPU
,x86
但我想在项目和失败的库的功能中,您应该将其值更改为x64
.
回答by ToFo
I fixed this by going to the Build menu (top pane) and say "Rebuild xxxProject.plugin" for that specific project only, contrary to building the entire solution.
我通过转到“构建”菜单(顶部窗格)并仅针对该特定项目说“重建 xxxProject.plugin”来解决此问题,这与构建整个解决方案相反。