News

InternalsVisibleTo and Unit Testing

2008-11-10 21:45:39 by Kjell-Åke Gafvelin

I’m posting this as a reminder for myself!

When doing unit testing of internal and private members of an assembly which has a strong name you have to add the InternalsVisibleToAttribute to it.

In C# it should look like this:

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("My.Assembly.UnitTest, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b942c093e3324a162084ae586f6de65ca4d79f82fd5e4939bd4a26ac5cfe0d42fae6b1b29e659a0710eb5b62e551bcde2494f17d3098f1dc664e0bf9e596e28effd9549bf4aff6dd3c00e28d66d7951ab86df06a8682070df557de4cfc8510ddb9fdb5de1c1f17235eaa3590d38114e4960a95820c375204050bc967c56a3c1")]

To get the public key from a strong named assembly you have to use sn.exe with the –Tp option.

This would give you the following result:

PS c:\....> sn -Tp My.Assembly.UnitTest.dll

Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.30729.1

Copyright (c) Microsoft Corporation.  All rights reserved.

Public key is

00240000048000009400000006020000002400005253413100040000010001002b942c093e3324

a162084ae586f6de65ca4d79f82fd5e4939bd4a26ac5cfe0d42fae6b1b29e659a0710eb5b62e55

1bcde2494f17d3098f1dc664e0bf9e596e28effd9549bf4aff6dd3c00e28d66d7951ab86df06a8

682070df557de4cfc8510ddb9fdb5de1c1f17235eaa3590d38114e4960a95820c375204050bc96

7c56a3c1

Public key token is 77a86484916e64d9

|