.NET 2.0 InternalsVisibleTo Attribute and Unsigned Assemblies
Ce post est disponible en francais ici.
In a recent project, for the purpose of unit testing, I had to use the InternalsVisibleTo attribute, which extends the scope of the internal qualifier. This allows the separation of the unit testing code assembly from the actual code, without publishing the internals to the "public". This way, you can avoid shipping your unit testing code.
This is an interesting attribute from many points of view, but when using it, you may face this nice error message :
error CS1726: Friend assembly reference 'Dummy' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.
Problem was, my current assembly nor the target assemblies were signed. I tried adding a dummy PublicKey or PublicKeyToken as indirectly suggested here and here, but as many people out here, I don't want to mess with assembly signing at this point of my project.
It turns out that the compiler considers your assembly as "signed" if there is either an AssemblyKeyFile or AssemblyKeyName defined on the assembly, even though both of them are empty.
So, to be able to use AssemblyKeyName InternalsVisibleTo with unsigned assemblies, just remove AssemblyKeyFile or AssemblyKeyName attributes if you don't use them.