by luisabreu via LA.NET [EN] on 6/9/2009 9:49:40 AM
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!!!
Original Post: Friend assemblies and strong names
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.