Unit testing strong-named assemblies in .NET

It’s been a couple of years since I first learned about the InternalsVisibleTo attribute.  It took until this afternoon to discover a problem with it.  This issue only occurs when you attempt to unit test internal classes of signed assemblies with an unsigned test assembly.  If you attempt to compile a Visual Studio solution in this case, the compiler will return the following complaint (among others):

Strong-name signed assemblies must specify a public key intheir InternalsVisibleTo declarations.

Thankfully, this blog post gives a great walk-through of how to get this working.  The instructions in brief:

  1. Sign your test assembly.
  2. Extract the public key.
  3. Update your InternalsVisibleTo argument to include the public key.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.