奇数错误的装配 [英] frind assembly with the odd error

查看:74
本文介绍了奇数错误的装配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在建设一些项目时遇到了麻烦.请考虑以下情况:

我有2个项目.例如A和B.
从A到B有一个参考
B的项目已被强烈签名(由于某些原因,我不希望它被签名.因此,我决定删除它的对程序集签名"的复选框)

A项目中的AssemblyInfo.cs文件中有一行代码说:

[assembly: InternalsVisibleTo("B,publicKey=0024......")]

我将其更改为:

[assembly: InternalsVisibleTo("B")]

现在,当我编译这些项目之一时,出现了一个错误,并说:

朋友程序集引用"B"无效.强名称签名的程序集必须在其InternalsVisibleTo声明中指定公钥.

我的问题在这里:编译器如何有一天知道它是一个已签名的程序集?以及如何完全从B的程序集中删除强符号并最终正确地构建它们?

顺便请注意,两个主题都没有强烈签名!因为我从那些项目的属性中删除了这两个为程序集签名"复选框

当我将程序集的名称更改为甚至不存在的某个错误名称(例如"bla_bla_bla")时,错误是相同的!
[assembly: InternalsVisibleTo("bla_bla_bla")]
我认为这个理论是正确的:
实际上,B项目没有编译,如果找不到匹配的已编译项目名称(在构建项目A时),则编译器会猜测B项目已使用开发人员未提供的公共密钥进行了强烈签名!最后会提示这种奇怪的错误!
由于B引用A的原因,当我编译B项目时,它将首先编译它的引用(A项目),然后编译器将提示我该错误(与我编译项目A时相同)

但是我的项目A要么不正确,要么出了点问题,因为我从头开始创建了两个新的简单项目,并且一切顺利,没有错误(即使我将[assembly:...]语句更改为无效程序集名称)我完全崩溃了

i have trouble with building some projects. please consider this scenario:

i have 2 projects. for example A and B.
there is a reference from A to B
project of B was strongly signed (i did not want it to be signed for some reasons. so i decided to remove it`s checkbox of "sign the assembly")

there was a line of code in AssemblyInfo.cs file in the A project says:

[assembly: InternalsVisibleTo("B,publicKey=0024......")]

i changed it to:

[assembly: InternalsVisibleTo("B")]

now when i compile one of these projects, an error has came up and says:

Friend assembly reference ''B'' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.

my question is here: how does compiler know that it was a signed assembly someday? and how can i completely remove strongly signed from assembly of B and finally build them correctly?

edited: by the way please note that both of theme is not strongly signed! because i remove both of those "sign the assembly" checkboxes from those project`s properties

when i changed the name of assembly to the some wrong name like "bla_bla_bla" that does not even exists, the error is the same!
[assembly: InternalsVisibleTo("bla_bla_bla")]
i think that this Theory is true:
in fact B Project does not compiled, and if it does not find the matched compiled project name (when building project A), compiler guess that B project is strongly signed with the public key that developer did not provide it! and at last it will prompt such odd error!
for the reason of B has a reference to A, when i compile B project, it will compile it''s reference first (A project) and again compiler will prompt me that error (as the same as when i comopile project A)

but either it`s not true or some thing is wrong with my project A. because i start two new simple projects from scratch and every thing goes fine with no error (even when i change [assembly:...] statement to the invalid assembly name) i completely crashed

推荐答案

这是MSDN在这上面要说的:

"如果您使用C#编译器来编译友好程序集,则您必须使用以下命令显式指定输出文件的名称(.exe或.dll). /out编译器选项.这是必需的,因为编译器在绑定到外部引用时尚未生成其正在生成的程序集的名称.使用F#编译器编译好友程序集时,不应使用基本编译器以及相应的--out或–o编译器选项."
- MSDN,InternalVisibleTo属性 [
This is what MSDN has to say on this:

"If you use the C# compiler to compile the friend assembly, you must explicitly specify the name of the output file (.exe or .dll) by using the /out compiler option. This is required because the compiler has not yet generated the name for the assembly it is building at the time it is binding to external references. The /out compiler option is optional for the Visual Basic compiler, and the corresponding --out or –o compiler option should not be used when compiling friend assemblies with the F# compiler."
—MSDN, InternalVisibleTo Attribute[^]
Does this help?

—MRB


我的天哪!我必须删除以下代码行:
Oh My God! i have to remove this line of code:
[assembly: AssemblyKeyName("")]


让projectA完全忘记签署项目并继续它的轻松生活
如您所知,是否对目标程序集进行了签名,因此也必须对引用的程序集进行签名.实际上,这行代码提醒编译器该项目已签名.所以...目标程序集也应该签名.因此,编译器会抱怨没有,publicKey = ..."令牌的朋友程序集.


so that projectA completely forget about signing project and continue it`s easy life
as you know if the destination Assembly was signed so referenced assembly must be signed too. in fact this line of code remind compiler that this project is signed. so... the target assembly should be signed too. therefore compiler complaint about having friend assembly with no " , publicKey=..." token.


您需要指定公共密钥令牌.参见 [
You need to specify the public key token. See this[^] article.

/ravi


这篇关于奇数错误的装配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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