3
votes

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

  1. i have 2 projects. for example A and B.
  2. there is a reference from A to B
  3. 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")
  4. 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

6
Build B, make sure it is correct. Then Remove and Re-Add the reference from A to B.Henk Holterman
yes i should rebuild B without A reference (that means i should comment all classes of project B) and then Rebuild A with changed AssemblyInfo.cs file and then uncomment all commented files in project B and rebuild B but there is still a problem! i commented and build B successfully but cant build A. it still did not recognized B is built (at lest i guess so)Rzassar

6 Answers

6
votes

I had the same issue and removing the following lines fixed it for me:

[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyName("")]

4
votes

Oh My God! i have to remove this line of code:
[assembly: AssemblyKeyName("")]
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.

3
votes

The compiler does not know that B was previously strongly named.

It does, however, know that A is strongly named. For security reasons, you can only expose the internals of a strongly-named assembly to another strongly-named assembly.

2
votes

It sounds like the problem is that A is signed - and you can't give "friend" access from a signed assembly to an unsigned assembly.

From the documentation:

Both the current assembly and the friend assembly must be unsigned, or both must be signed with a strong name.

I'm not entirely sure that it's correct - I'd expect an unsigned assembly to be able to give access to a signed assembly, but that's irrelevant to your current situation :)

EDIT: After your update, I suspect the simplest way to proceed is simply to clean the solution then rebuild.

2
votes

If neither of your assemblies are signed and you're getting the error, and you have the previously mentioned lines in your AssemblyInfo file, then they can be the culprit.

But as JoeGeeky mentions, you have to remove both of these lines from your AssemblyInfo file for the compiler to no longer think it is a signed assembly:

// both/either cause compiler to think assembly is signed
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

This one will also cause the same issue (notice the true):

// also causes compiler to think assembly is signed
[assembly: AssemblyDelaySign(true)]

However, if it's set to false, then it doesn't trigger the error (but if you have it in there you may as well remove it too).

// does not cause compiler to think assembly is signed
[assembly: AssemblyDelaySign(false)]
0
votes
[assembly: AssemblyDelaySign(false)]

//[assembly: AssemblyKeyFile("")]
//[assembly: AssemblyKeyName("")] 

Commenting 2 lines resolved issue for me