In order to write unit tests for class marked as internal you will have to add InternalsVisibleTo attribute to your signed assembly, in order to expose those classes to the unit tests project. That poses a problem when the assembly you are testing is signed, and most likely you will get an error with a similar message “Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations”.

To solve the problem and continue on your way of testing your classes, simply sign your unit test project, and then add the public key to the InternalsVisibleTo declaration. Something like:
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("TestAssembly, PublicKey=......")]

Notice the fact that the public key reference is specified with only “PublicKey” and not with “PublicKeyToken”, which is what you would use if you normally reference a signed assembly.

 

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Set your Twitter account name in your settings to use the TwitterBar Section.