引用的程序集没有强名称

引用的程序集没有强名称

本文介绍了如何修复“引用的程序集没有强名称"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 Visual Studio 2005 项目(其中被强命名).我现在收到错误:

I've added a weakly named assembly to my Visual Studio 2005 project (which is strongly named). I'm now getting the error:

引用的程序集 'xxxxxxxx' 没有强名称"

我需要签署这个第三方程序集吗?

Do I need to sign this third-party assembly?

推荐答案

要避免此错误,您可以:

To avoid this error you could either:

  • 动态加载程序集,或
  • 签署第三方程序集.

您将在.NET-fu:签署未签名的程序集(无延迟签名).

签署thirp-party的基本原则是

The basic principle to sign a thirp-party is to

  1. 使用 ildasm.exe 反汇编程序集并保存中间语言 (IL):

  1. Disassemble the assembly using ildasm.exe and save the intermediate language (IL):

ildasm /all /out=thirdPartyLib.il thirdPartyLib.dll

  • 重建并签署程序集:

  • Rebuild and sign the assembly:

    ilasm /dll /key=myKey.snk thirdPartyLib.il
    

  • 修复其他参考

    上述步骤工作正常,除非您的第三方程序集 (A.dll) 引用另一个也必须签名的库 (B.dll).您可以使用上述命令对 A.dllB.dll 进行反汇编、重建和签名,但在运行时,加载 B.dll将失败,因为 A.dll 最初是使用对 B.dll未签名 版本的引用构建的.

    Fixing Additional References

    The above steps work fine unless your third-party assembly (A.dll) references another library (B.dll) which also has to be signed. You can disassemble, rebuild and sign both A.dll and B.dll using the commands above, but at runtime, loading of B.dll will fail because A.dll was originally built with a reference to the unsigned version of B.dll.

    解决此问题的方法是修补上述步骤 1 中生成的 IL 文件.您需要将 B.dll 的公钥标记添加到引用中.您可以通过调用

    The fix to this issue is to patch the IL file generated in step 1 above. You will need to add the public key token of B.dll to the reference. You get this token by calling

    sn -Tp B.dll
    

    这将为您提供以下输出:

    which will give you the following output:

    Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.33440
    Copyright (c) Microsoft Corporation.  All rights reserved.
    
    Public key (hash algorithm: sha1):
    002400000480000094000000060200000024000052534131000400000100010093d86f6656eed3
    b62780466e6ba30fd15d69a3918e4bbd75d3e9ca8baa5641955c86251ce1e5a83857c7f49288eb
    4a0093b20aa9c7faae5184770108d9515905ddd82222514921fa81fff2ea565ae0e98cf66d3758
    cb8b22c8efd729821518a76427b7ca1c979caa2d78404da3d44592badc194d05bfdd29b9b8120c
    78effe92
    
    Public key token is a8a7ed7203d87bc9
    

    最后一行包含公钥令牌.然后,您必须在 A.dll 的 IL 中搜索对 B.dll 的引用,并添加如下标记:

    The last line contains the public key token. You then have to search the IL of A.dll for the reference to B.dll and add the token as follows:

    .assembly extern /*23000003*/ MyAssemblyName
    {
      .publickeytoken = (A8 A7 ED 72 03 D8 7B C9 )
      .ver 10:0:0:0
    }
    

    这篇关于如何修复“引用的程序集没有强名称"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    07-25 01:53