I try to use the MoqMockingKernel class. (Ninject.MockingKernel.Moq) from the Ninject.MockingKernel Extension for a unit test.
At initializing the MoqMockingKernel I'm getting the following error:
System.TypeLoadException: System.TypeLoadException: Inheritance security rules violated by type: 'Ninject.MockingKernel.MockingKernel'. Derived types must either match the security accessibility of the base type or be less accessible..
My initializing code:
private MoqMockingKernel mockingKernel;
private Mock<IUnitOfWork> unitOfWorkMock;
private IExternalServiceRepository externalServiceRepository;
[TestInitialize]
public void Initialize()
{
this.mockingKernel = new MoqMockingKernel();
this.mockingKernel.Bind<IUnitOfWork>().ToMock();
this.unitOfWorkMock = this.mockingKernel.GetMock<IUnitOfWork>();
externalServiceRepository = new ExternalServiceRepository { Kernel = this.mockingKernel };
}
How can I solve this TypeLoadException
?
Are you using .Net framework >= 4.0?
See this conversation
I took advice from those instructions: I modified MockingKernel source code by adding this line
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
to AssemblyInfo.cs in projects Ninject.MockingKernel and Ninject.MockingKernel.Moq. Then I recompiled solution, installed dll's and my code started to work!
I hope this is the trick for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With