TypeLoadException when mocking COM objects - Could not load type … from assembly. The type is marked…

Written on April 20, 2011

When it comes to mocking COM objects (using the Mock Framework of your choice) you may face the following exception:

System.TypeLoadException: Could not load type 'IModelDoc2Proxy52849244002f4ce4a339ed6a97d23841' from assembly 'DynamicProxyGenAssembly2, Version=, Culture=neutral, PublicKeyToken=null'. The type is marked as eligible for type equivalence, but either it has generic parameters, or it is not a structure, COM imported interface, enumeration, or delegate.

If you're working with .NET Framework 4.0, it is likely that it is caused by the "Embed Interop Types" property of the Reference being set to "True" (which is the default):

Interop Reference

Just another reason to set it to "False" by default.

DotNetKicks-DE Image