InternalsVisibleToAttribute to support unit testing of nonpublic types

My colleague wouter spotted this new feature in the .NET 2.0 framework.


This attribute gives you the ability to do an Animal Farm trick.. all assemblies are equal, but some assemblies are more equal in the fact that they are allowed to access your internal stuff.


This solves a problem we’ve had with unittesting. Because we always use a separate project (assembly) to contain the unit tests (as VS2005 does also), you cannot access internal classes etc. By giving the unit test assembly rights to your business logic assembly, this problem can be solved, because we are then able to also access all nonpublic types. I bet this is probably also the reason why this attribute was invented, because in other cases it would be mostly bad design when you need these kinds of attributes…


This also does away will all kinds of nasty tricks used in the past, such as using reflection to access nonpublic types.


Another reason to switch to .NET 2.0 I think