Mocking an internal interface with Moq

If by some reason you need to Mock an internal interface using Moq, you might get the infamous exception while running your unit tests:
System.TypeLoadException : Type 'ISomething`1ProxyRandomGuid' from assembly 'DynamicProxyGenAssembly2, Version=, Culture=neutral, PublicKeyToken=YetAnotherGuid' is attempting to implement an inaccessible interface.

Assuming that you already added the InternalsVisibleTo from your library to your unit test project, you'll also need to add an InternalsVisibleTo to DynamicProxyGenAssembly2. However, unlike the author in the blog post, in my machine it only works if I remove the PublicKey, something like:


No comments:

Post a Comment