Allowing Your Assmbly to Properly Declare it’s Public Interfaces

I have been looking at Enterprise Library 3.0 more this weekend and discovered something I thought was noteworthy.
If you have an assembly that has members that you want available to another assembly (say, a test assembly), but don’t want have all your internal types visible to other client assemblies, you can use the InternalsVisibleToAttribute in your AssemblyInfo.cs.
A common complaint about unit testing is that you have to make everything public and accessible, possibly breaking your intended design for the sake of testability. You can correct that issue by adding this attribute to your target assembly’s AssemblyInfo.cs file:
[assembly: InternalsVisibleTo("MyTestAssembly")]
If the assembly that you are trying to make the internals visible from is signed with a strong-name key, you need to specify the PublicKey of the strong-name key that you signed your assembly with.
To find out the Public Key of your assembly you can issue the following commands:
sn.exe -p MyKey.snk
sn.exe -tp
Then  you can assign the PublicKey value in the InternalsVisibleToAttribute as follows:
[assembly: InternalsVisibleTo("MyTestAssembly, PublicKey=



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s