对没有强名称的程序集的引用 [英] Reference to assembly without strong name

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

问题描述

有没有办法引用没有强名称的库?当我在引用和重建解决方案中添加对程序集的引用时,一切都很好,但是当我从这个程序集解决方案中调用类时,它不会构建.

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.

如果您真的无法为被引用的名称添加强名称,或者从进行引用的名称中删除强名称(对不起,啰嗦),那么您将不得不在运行时通过反射来绑定类,然后通过公共基础或接口访问它 - 根本不理想;甚至更糟的是通过反射或 dynamic 实际调用它.

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.

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

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