NMock2 Doesn't Mock Concrete Classes

By Mithun Bose at February 19, 2010 16:36
Filed Under: Troubleshooting, Test Driven Development

Today while running unit tests using NUnit and NMock2 framework, I stumbled upon following error.

System.TypeLoadException : Could not load type 'MultiInterface1' from assembly 'Mocks, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because it attempts to implement a class as an interface.

This error message is very specific but probably isn't very obvious. The only time you will get this error is when you try to mock a concrete class object rather than an interface using NMock2 framework. I overlooked the fact that I was mocking a concrete class. I decided to post this because I didn't see much of help pages on this topic after googling it.

 

About the author

I am a professional software developer based in London, England. I specialize in developing enterprise application and integration framework in C#, SQL Server, ASP.NET. 

My area of interests include SOA using WCF, Web, Business Intelligence and Database programming. I am a Computer Science Graduate and Microsoft Certified Professional Developer in enterprise application.