简体   繁体   English

.net-添加了一个强大的命名程序集,但是它正在寻找未签名的程序集

[英].net - Added a strong named assembly, but it is looking for unsigned assembly

So, I have two projects... One is a big class library, and the other is a big simulator project. 因此,我有两个项目……一个是大型类库,另一个是大型模拟器项目。

Originally during testing the assemblies were not strong-named, but now that I need COM visibility, I need to strong name them (I need this quick, and it is easier to make them COM visible rather than deal with the CLI). 最初,在测试过程中,程序集不是用强名称命名的,但是现在我需要COM可见性,所以我需要对它们进行强命名(我需要这种快速操作,使它们对COM可见而不是对CLI进行处理更容易)。

I generated a .snk and added it to the properties of each of the projects, the class library compiles just fine and outputs the .dll just fine. 我生成了一个.snk并将其添加到每个项目的属性中,该类库可以很好地进行编译,并且可以很好地输出.dll。 I added this .dll as a reference in the simulator project, but now the simulator project is giving me the following error: 我在模拟器项目中添加了该.dll作为参考,但是现在模拟器项目给了我以下错误:

The type "DynamicsControl" is defined in an assembly that is not referenced. 在未引用的程序集中定义了“ DynamicsControl”类型。 You must add a reference to assembly "DynamicsControl, Version=0.4.3.0, Culture=neutral, PublicKeyToken=null" 您必须添加对程序集“ DynamicsControl,Version = 0.4.3.0,Culture = neutral,PublicKeyToken = null”的引用

The type DynamicsControl does exist in the class library (I verified), but it is claiming I am not loading the correct assembly. 类库中确实存在类型DynamicsControl(我已验证),但是它声称我没有加载正确的程序集。 I believe it is the PublicKeyToken=null that is causing the issue (as my assembly would have a public key). 我认为是导致问题的原因是PublicKeyToken = null(因为我的程序集将具有公共密钥)。

When I do sn -Tp DynamicsControl.dll (the one in the location I am referencing), it outputs the private and public key, so I know it has a proper signature. 当我执行sn -Tp DynamicsControl.dll(我要引用的位置中的那个)时,它会输出私钥和公钥,因此我知道它具有正确的签名。

What step am I missing? 我想走哪一步? Do I have to add the assembly to the GAC? 我是否必须将程序集添加到GAC? Do I manually have to add the public key? 我是否必须手动添加公钥?

Yes you need to specify the publicKeyToken for a strong named assembly otherwise it will look for unsigned version of the assembly. 是的,您需要为强命名程序集指定publicKeyToken,否则它将查找该程序集的未签名版本。 You can find out the public key token either by adding the assembly to GAC (and you will see it there) or by using the steps mentioned in the this link 您可以通过将程序集添加到GAC(您将在此处看到它)或使用此链接中提到的步骤来找到公钥令牌。

If you want to read more about strong name and dll hell you can go to this URL . 如果您想了解有关强名和dll的更多信息,可以转到此URL

Strong name prevents from dll hell which means you can have multiple versions of same assembly. 强名防止dll地狱,这意味着您可以具有同一程序集的多个版本。

To your other question you don't have to add the assembly to GAC but CLR will look for the assembly first in GAC and then other places. 对于您的其他问题,您不必将程序集添加到GAC中,但是CLR会先在GAC中查找程序集,然后再在其他地方查找。 Also, you don't have to add the key manually. 另外,您不必手动添加密钥。 If you remove the reference and add it back using the signed assembly it should automatically take the key. 如果删除引用并使用已签名的程序集将其重新添加,则它应自动获取密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM