【发布时间】:2012-08-12 23:34:29
【问题描述】:
我有类似的代码
using FluentValidation;
public class FreeformValidator : AbstractValidator<Freeform>
{
public FreeformValidator() // <-- VerificationException on this line
{
RuleFor(ff => ff.Text).Must(BeLongEnough).WithMessage("Must be at least {0} characters.", ff => ff.MinLength);
}
}
由单元测试运行。在针对 .Net 4 的 VS 2010 下,单元测试运行良好。更新到 VS 2012 并针对 .Net 4.5 后,单元测试抛出
验证异常
操作可能会破坏运行时的稳定性。
异常对话框提示
确保您的应用程序没有加载两个相互冲突的类库版本。
AbstractValidator 来自 FluentValidation。正在测试的项目和单元测试项目都参考 FluentValidation 3.3.1.0。这两个项目现在也都针对 .Net 4.5。
这两个项目都以 AnyCPU 为目标。该代码在 Windows 7 64 位上运行。
更新
这是单元测试代码
[TestMethod]
public void FreeformValidation_MinLength()
{
Freeform fa = new Freeform();
fa.Required = true;
fa.MinLength = 3;
fa.MaxLength = 10;
FreeformValidator fv = new FreeformValidator();
fa.Text = "AB";
ValidationResult results = fv.Validate(fa);
Assert.AreEqual(1, results.Errors.Count, "Expected MinLength to fail.");
Assert.AreEqual("Must be at least 3 characters.", results.Errors[0].ErrorMessage, "Expected MinLength to fail.");
}
更新 2
可能相关
System.Security.VerificationException after installation VS 2012
但是,将配置切换到 x86 并重新运行测试会导致相同的异常。
似乎不适用的类似问题
How can I prevent a VerificationException when running a test with attached debugger?
单元测试在没有调试器的情况下以同样的方式失败,并且将 FluentValidator 添加到 IntelliTrace 排除列表没有帮助。
Operation could destabilize the runtime?
我没有强命名程序集,也没有 AllowPartiallyTrustedCallers 属性。
更新 3
PEVerify 发现测试项目的 DLL 或正在测试的 DLL 没有问题。
【问题讨论】:
-
哪个测试框架?哪个测试员?你可以发布你的单元测试吗?
-
使用内置的测试框架。认为它被称为 mstest?
-
你试过了吗:this。专门使用 PEVerify 来获取错误的更多详细信息?
-
PEVerify 表示测试的 dll 或测试项目的 dll 都没有问题。
-
你用的是什么版本的VS2012? Intellitrace 可能会导致此问题,但仅适用于 Ultimate 版。您可以将 FluentValidation 添加为 Intellitrace 设置中的排除模块。但是,我遇到了这个确切的问题,但使用的是高级版。