如何修复"引用程序集不具有强名称"错误? [英] How to fix "Referenced assembly does not have a strong name" error?

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

问题描述

我添加了一个名为弱装配到我的<一个href=\"http://en.wikipedia.org/wiki/Microsoft_Visual_Studio#Visual_Studio_2005\">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不具有强名称

"Referenced assembly 'xxxxxxxx' does not have a strong name"

我是否需要签署该第三方组件?

Do I need to sign this third-party assembly?

推荐答案

要避免这个错误,你既可以:

To avoid this error you could either:


  • 加载动态组装,或者

  • 登入第三方组件。

您会发现在的 <一个签约的第三方组件的说明href=\"http://buffered.io/post/2008-07-09-net-fu-signing-an-unsigned-assembly-without-delay-signing/\">.NET-fu:签署无符号大会(无延迟签名) 的。

You will find instructions on signing third-party assemblies in .NET-fu: Signing an Unsigned Assembly (Without Delay Signing).

签署thirp党的基本原理是将

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.DLL 的和的 B.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
    

    最后一行包含公钥标记。然后,您可以搜索的IL的 A.DLL 的为参考的 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*/ Eurolook.Common
    {
      .publickeytoken = (A8 A7 ED 72 03 D8 7B C9 )                         
      .ver 10:0:0:0
    }
    

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

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆