Reference to assembly without strong name

有些话、适合烂在心里 提交于 2019-12-22 03:25:26

问题


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.


回答1:


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.




回答2:


The whole point of a strong name is that you know what dlls are getting loaded. 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). 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)
  • or; rebuild the dll you are referencing with a strong-name
  • or; load the additional dll only through reflection (yuck)


来源:https://stackoverflow.com/questions/6370753/reference-to-assembly-without-strong-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!