Weird .net 4.0 exception when running unit tests

Posted by vdh_ant on Stack Overflow See other posts from Stack Overflow or by vdh_ant
Published on 2010-04-22T22:47:06Z Indexed on 2010/04/26 21:23 UTC
Read the original article Hit count: 337

Hi guys I am receiving the following exception when trying to run my unit tests using .net 4.0 under VS2010 with moq 3.1.

Attempt by security transparent method 'SPPD.Backend.DataAccess.Test.Specs_for_Core.When_using_base.Can_create_mapper()' to access security critical method 'Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(System.Object)' failed.

Assembly 'SPPD.Backend.DataAccess.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.

The test I am running is really straight forward and looks something like the following:

    [TestMethod]
    public void Can_create_mapper()
    {
        this.SetupTest();

        var mockMapper = new Moq.Mock<IMapper>().Object;
        this._Resolver.Setup(x => x.Resolve<IMapper>()).Returns(mockMapper).Verifiable();

        var testBaseDa = new TestBaseDa();
        var result = testBaseDa.TestCreateMapper<IMapper>();

        Assert.IsNotNull(result);  //<<< THROWS EXCEPTION HERE 
        Assert.AreSame(mockMapper, result);

        this._Resolver.Verify();
    }

I have no idea what this means and I have been looking around and have found very little on the topic. The closest reference I have found is this http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=80274 but its not very clear on what they did to fix it...

Anyone got any ideas?

© Stack Overflow or respective owner

Related posts about .net-4.0

Related posts about unit-testing