Eri*_* J. 6 .net visual-studio-2012
我的代码就像
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);
}
}
Run Code Online (Sandbox Code Playgroud)
由单元测试运行.在VS 2010目标.Net 4下,单元测试运行良好.更新到VS 2012并以.Net 4.5为目标后,单元测试将被抛出
VerificationException
操作可能会破坏运行时的稳定性.
异常对话框建议
确保您的应用程序未加载类库的两个冲突版本.
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.");
}
Run Code Online (Sandbox Code Playgroud)
更新2
可能有关系
安装VS 2012后出现System.Security.VerificationException
但是,将配置切换到x86并重新运行测试会导致相同的异常.
类似的问题似乎不适用
如何在使用附加调试器运行测试时阻止VerificationException?
单元测试在没有调试器的情况下以相同的方式失败,并且将FluentValidator添加到IntelliTrace排除列表没有帮助.
我没有强名称程序集,也没有AllowPartiallyTrustedCallers属性.
更新3
PEVerify发现测试项目的DLL或正在测试的DLL没有问题.
看起来CLR团队特别建议修复:
修复了.net 4.5反射错误将CLR团队建议的修复程序应用于AbstractValidator和DelegateValidator类型.
https://github.com/thecodejunkie/FluentValidation/commit/ddc1d7235b9c122c06fd224e8490b94791a715c0
| 归档时间: |
|
| 查看次数: |
2362 次 |
| 最近记录: |