Unity can't resolve a dynamically mocked class


  • Solution uses prism
  • Modules Project which is written in VB
  • Test Project which is written in C#

In my unit tests I mock up services which are used by modules and pass them, however when module tries to resolve, it fails with the following exception

    {"Resolution of the dependency failed, type = "UnderwritingWorkflow.Common.Services.IValidationService", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, UnderwritingWorkflow.Common.Services.IValidationService, is an interface and cannot be constructed. Are you missing a type mapping?

At the time of the exception, the container was:

Resolving UnderwritingWorkflow.Common.Services.IValidationService,(none) "}

Here is the code for registering object with UnityContainer:

var validationService = new Mock<IValidationService>(MockBehavior.Strict);

validationService.Setup(x => x.Validate(Moq.It.IsAny<object>()))
                 .Returns(() => new ValidationResults());


Also if try resolving IServiceValidation from c# straight after registering it (from within the constructor) seems to work:


Any ideas why this is happening?

Note: I am using Moq mocking framework which creates classes in runtime and I wonder if it is the limitation of VB which doesn't allow me to use it?


I found what was causing this issues, it is the limitation of the Moq framework. Aparently Moq can't mock static methods, including extension methods and Container.Resolve is an extension method, hence it fails.

Need Your Help

bash_profile not working as it should

linux path environment-variables

Hi Im running linux angstrom distribution on a remote device, I added .bash_profile and .bashrc to /home/root since they didn't exist and I wrote this in them

Visual Studio Extensions: Editing code files in the current solution?

c# visual-studio-2010

Is there a way to get a list of all of the .cs files in a solution, and edit them using the vs2010 interface?