首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何诊断“强名称验证失败”。0x8013141A错误

如何诊断“强名称验证失败”。0x8013141A错误
EN

Stack Overflow用户
提问于 2022-04-27 09:01:58
回答 2查看 582关注 0票数 1

我有一个为.NET Framework4.8编译的工具,它使用NuGet包Microsoft.VisualStudio.Services.Client,其中包含一个程序集Microsoft.VisualStudio.Services.Common

该工具在大多数机器上运行良好,但在某些机器上却失败了:

代码语言:javascript
运行
复制
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.VisualStudio.Services.Common, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
File name: 'Microsoft.VisualStudio.Services.Common, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A)
The Zone of the assembly that failed was:
MyComputer

我已经检查过了,在这两种情况下,它都使用完全相同的.NET框架(4.8)运行。我试图检查融合日志,但是那里没有报告错误,即使是导致它报告成功的问题的程序集也是如此。

(在.NET 6上使用相同的代码。)

我的问题是,怎样才能诊断出这类问题?有什么我能查的线索吗?

更新:反思@CherryDT的评论:奇怪的是,使用sn.exe工具跳过验证也没有帮助:

代码语言:javascript
运行
复制
C:\Users\<user>\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\net48>sn -Vr Microsoft.VisualStudio.Services.Common.dll

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Verification entry added for assembly 'Microsoft.VisualStudio.Services.Common,B03F5F7F11D50A3A'

C:\Users\<user>\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\net48>sn -Vl

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly/Strong Name                  Users
===========================================
Microsoft.VisualStudio.Services.Common,B03F5F7F11D50A3A All users

C:\Users\<user>\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\net48>sn -v Microsoft.VisualStudio.Services.Common.dll

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly 'Microsoft.VisualStudio.Services.Common.dll' is valid
Assembly 'Microsoft.VisualStudio.Services.Common.dll' is verified with a key other than the identity key

C:\Users\<user>\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\net48>ConsoleApp1.exe

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.VisualStudio.Services.Common, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A) ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A)
   --- End of inner exception stack trace ---
   at Program.<Main>$(String[] args)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-04-27 10:35:59

我终于找到原因了。(感谢@CherryDT迫使我再次检查sn.exe。)

问题是,程序集的签名确实是错误的,但是在没有导致错误的机器上,对于所有程序集(*,*)都有一个全局强名称验证忽略,这很可能是某个应用程序安装程序早些时候悄悄添加的。(在不通知我的用户的情况下做这样的事情是非常不友好的。)

我之前没有意识到这一点的原因是,我使用的是x86版本的sn.exe,而不是应用程序使用的x64版本。

最后,我使用了一个不同版本的依赖项来解决这个问题,其中已经解决了签名问题。

因此,结论是,我应该始终确保使用正确的sn.exe版本(有关如何使用的详细信息,请参见https://stackoverflow.com/a/18760340/26530 )。

票数 3
EN

Stack Overflow用户

发布于 2022-09-02 12:11:34

可以使用以下命令跳过强名称验证。

对于x64机器,

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\sn.exe" -Vr *,*请注意,我们使用的是x64版本的sn.exe

对于x32机器,

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\sn.exe" -Vr *,*请注意,我们使用的是x32版本的sn.exe

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72026072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档