Before getting started, I’d like to say that I don’t really use friend assemblies much. However, there are times where using friend assemblies is a must and in those cases, you might end up getting into the problem I had. For starters, you need to use the InternalsVisibleToAttribute to signal a friend assembly. In my case, I’ve added something like this:
[assembly: InternalsVisibleTo("Sra.Core.Entities.Repositories")]
Since I tend to sign my assemblies, I’ve ended up getting this error:
error CS1726: Friend assembly reference ”Sra.Core.Entities.Repositories” is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.
hum…nice…I’ll just get the PublicKey from Reflector and we’re done here! Oh, not quite…When I tried adding something like this:
[assembly: InternalsVisibleTo("Sra.Core.Entities.Repositories, PublicKey=1231ab00a0d…")]
“Now I’m done!”…at least, that’s what I thought…However, I ended up getting the same error…wtf? It was then that I read the following on the docs:
“This attribute applies to internal types in C#, friend types in Visual Basic,and all types at namespace or global scope in C++. To apply this attribute to a strong-named friend assembly,you must know the hexadecimal string that represents the public key of the friend assembly.”
Aha! hexadecimal…that’s it…I’ll just convert it to hexadecimal…now the thing is: what is the quickest way to get the key in hexadecimal? If you’re thinking reflector, you’re right! Just change the language to IL and you’ll get your key in hex:
You gotta love Reflector!!!