gpt4 book ai didi

unit-testing - 运行单元测试时出现奇怪的 .net 4.0 异常

转载 作者:行者123 更新时间:2023-12-02 12:52:36 24 4
gpt4 key购买 nike

当我尝试在 VS2010 下使用 .net 4.0 和最小起订量 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.

我正在运行的测试非常简单,如下所示:

    [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();
}

我不知道这意味着什么,我一直在环顾四周,但在这个主题上发现的很少。我找到的最接近的引用文献是这个http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=80274但不太清楚他们做了什么来修复它......

大家有什么想法吗?

最佳答案

在引用项目的 AssemblyInfo.cs 中添加以下行

[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

关于unit-testing - 运行单元测试时出现奇怪的 .net 4.0 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2695049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com