MoqMockingKernel: System.TypeLoadException: Inheritance security rules violated by type
Asked Answered
H

1

6

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?

Heretofore answered 8/11, 2012 at 10:7 Comment(0)
E
5

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.

Erne answered 25/2, 2013 at 5:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.