Confusion
The other day I ended up making the decision to strong name a series of assemblies. It also usually means revisiting some config files somewhere and re-referencing the same dll's all over again but with a strong name. Of course there's many benefits to strong naming but that's not what this is about.
What I DIDN'T see coming was how this would throw a wrench into my unit tests. Normally when you create Unit Tests under Visual Studio if you are testing internal (friend in VB) methods it will automagically add the System.Runtime.CompilerServices.InternalsVisibleTo attribute on the assembly that is going to be unit tested. But the moment I strong named the assembly I wanted to run tests on I ended up getting the following error:
I dug through some MSDN documentation and found that it wanted me to do just that, instead of:
It took a bit of thinking for this to finally make sense to me. Strongly Named assemblies don't mind exposing their internals to other assemblies, but they'd at least like them to also be strongly named AND have have us specify the public of any assembly that's going to be digging around in its internals.
This means we have to strong name the Unit Test assembly as well.
In addition we still need to get the Public Key off of the Unit Test assembly after we strong name it.
It's important to note that the PublicKey is NOT the PublicKeyToken that you might acquire through Reflector and is part of the strong name. The PublicKey is the value of the public key extracted from the Key Pair/.snk file with the sn.exe utility.
Solution
You can extract the public key from an .snk with the sn.exe tool from the .NET SDK. First we extract just the public key from the key pair (.snk) file into another .snk file.
We end up getting a super LONG string of hex, but that's just what we want, the public key value of this key pair.
We add it to the strongly named project that we want to expose our internals from and we're good to go. Before what looked like:
And we're done.
Hope that helps,
Tyler
12 comments:
Wow, thank you so much. You save me from evil thinking converting internal to public for testing :D
Thanks,
Its really a helpfull information.
But even after following all step properly i was getting another error as "Friend access was granted to test project".
i signed my test project with the same key. it started working fine. Didnt see this info in your blog. so thouhgt of adding it..
Thanks Jocker, appreciate the feedback.
Best,
Tyler
Thanks! This article was very helpful and saved me many hours of digging and experimentation.
Congratulations, your blog is appealing and informative. Going through your Information, I found quite a few new ideas to implement.
It’s a really amazing powerful resource that you’re offering and you just provide it away cost-free!! I that can compare with discovering websites which be aware of the particular in supplying you with fantastic learning resource for zero cost. We truly dearly loved examining these pages. Appreciate it! The Tre Ver Condo Location Singapore
VILLAS FOR SALE IN CASABLANCASpainForSale.Properties is considered one of the most trusted Exclusive Real Estate Agencies in Marbella, Costa del Sol and other “Prime Locations” in Spain.Live on the Costa del Sol and Enjoy a Luxurious lifestyle in one of the most beautiful places of the World.
You have remarked very interesting details! ps decent website. “Pray To ask that the laws of the universe be annulled in behalf of a single petitioner confessed unworthy.” by Ambrose Gwinett Bierce.. real estate agent
This is my new I’ve visited here. I discovered plenty of interesting information inside your blog. In the a lot of comments within your posts, I suppose Im not alone! continue the impressive work. isla mujeres real estate
I love blogging and i can say that you also love blogging . Boulevard 88 Price
I read your web journal every now and again and I just thought I'd say keep up the astonishing work! Piermont Grand Sumang Walk
Exactly what I was searching for, thankyou for posting . hotel
Post a Comment