简体   繁体   English

参考没有强名称的汇编

[英]Reference to assembly without strong name

Is there a way to reference a library without a strong name? 有没有办法引用没有强名称的库? When I add a reference to the assembly in references and rebuild solution everything is fine, but when I call the class from this assembly solution it doesn't build. 当我在引用中添加对程序集的引用并重建解决方案时,一切都很好,但是当我从这个程序集解决方案调用该类时,它不会构建。

Output says that referenced assembly should have strong name. 输出表示引用的程序集应具有强名称。 What is the best solution? 什么是最好的解决方案? Strong naming library is not preferable. 强命名库不是首选。

I think the problem you have here is that the assembly you are trying to add the reference from is being signed with a strong name but the assembly you are trying to reference is not signed. 我认为你在这里遇到的问题是你试图添加引用的程序集是用强名称签名的,但你试图引用的程序集没有签名。 A strong-named assembly can only reference other strong-named assemblies. 强名称程序集只能引用其他强名称程序集。

Either sign the assembly you are referencing or don't sign the assembly that is referencing it. 对要引用的程序集进行签名,或者不对引用它的程序集进行签名。

The reason why the error only appears when you actually call the class is because the compiler will strip out the reference in the compiled output if there is no code actually invoking the referenced assembly. 实际调用类时出现错误的原因是,如果没有实际调用引用程序集的代码,编译器将在编译输出中删除引用。

If it's the case that you really can't either add a strong name to the one being referenced, or remove the strong name from the one doing the referencing (sorry long-winded) then you are going to have to look at binding the class at runtime via reflection and then accessing it via a common base or interface - not ideal at all; 如果你真的无法为被引用者添加强名称,或者从执行引用的名称中删除强名称(抱歉啰嗦),那么你将不得不看看绑定类在运行时通过反射然后通过公共基础或接口访问它 - 根本不理想; or even worse actually invoking it via reflection, or dynamic . 甚至更糟糕的是通过反射或dynamic调用它。

The whole point of a strong name is that you know what dlls are getting loaded. 一个强有力的名字的重点是你知道什么dll被加载。 You can't add a strong-name to your dll if you reference something that isn't strong-named, as anything could be loaded in place of the dll you are thinking of (as long as the name matches). 如果您引用的内容不是强名称,则无法为您的 dll添加强名称,因为可以加载任何内容来代替您正在考虑的dll(只要名称匹配)。 This entirely defeats the guarantees that a strong name is intended to provide. 这完全违背了强名称旨在提供的保证。

So (one of): 所以(其中之一):

  • don't add a strong-name to your dll (for most internal things, you just don't need one) 不要为你的dll添加一个强名称(对于大多数内部事物,你只需要一个)
  • or; 要么; rebuild the dll you are referencing with a strong-name 使用强名称重建您引用的dll
  • or; 要么; load the additional dll only through reflection (yuck) 仅通过反射(yuck)加载附加dll

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

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