InternalsVisibleTo attribute is a well-known attribute for testing assemblies. The internal methods of an assembly become visible to the test project. This allows you to test the internal methods without using reflection, so your tests are more maintainable.
If the assembly does not have a strong name, you can easily add the
[assembly: InternalsVisibleTo("TestProject")] // The TestPrject will have access to the internal types and members
public static class Sample
internal void Fibonacci(int n)
public class Test
public void TestFibo()
Sample.Fibonacci(0); // No error
However, if the assembly has a strong name, the name of the assembly must include the PublicKey. Getting the PublicKey, not the PublicKeyToken, is not very convenient. As I don't want to remember the procedure, here's the steps.
I suppose you already have a snk file
sn.exe in the Windows SDK (C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin)
- Extract the public key of the snk file
sn.exe -p file.snk file.PublicKey
- Get the readable version of the public key
sn.exe -tp SomeName.PublicKey
It shoud print a long sequence of digits and letters in the console.
- Copy the public key in the
[assembly: InternalsVisibleTo("ProjectTest, PublicKey=002400000...")]
If you do not copy the expected public key, you'll get a compilation error.
Do you have a question or a suggestion about this post? Contact me!