[英]How can I prevent the debugger from entering my method when Exception is thrown?
[英]How can I prevent a VerificationException when running a test with attached debugger?
每當我運行附加調試器的以下任一單元測試時,此時我在FluentValidation代碼中得到一個VerificationException
(如果需要,稍后將發布整個堆棧跟蹤 ):
at FluentValidation.Resources.LocalizedStringSource.CreateFromExpression(Expression`1 expression, IResourceAccessorBuilder resourceProviderSelectionStrategy)
in ...\FluentValidation\Resources\LocalizedStringSource.cs:line 66
測試是:
using FluentValidation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var c = new MyClass();
var v = new MyValidator();
v.Validate(c);
}
[TestMethod]
public void TestMethod2()
{
Exception ex = null;
var done = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(
o =>
{
try
{
TestMethod1();
}
catch (Exception e)
{
ex = e;
}
finally
{
done.Set();
}
});
done.WaitOne();
Assert.IsNull(ex);
}
}
public class MyValidator : AbstractValidator<MyClass>
{
public MyValidator()
{
RuleFor(c => c.MyProperty).GreaterThan(0);
}
}
public class MyClass
{
public int MyProperty { get; set; }
}
我在單一解決方案,單項目場景中引用了這些程序集,目標是4.0.30319運行時:
其他一些觀點:
SecurityRulesAttribute
應用於類似的問題 有誰知道如何防止這種VerificationException
,解決它,和/或它為什么會被造成? 似乎有這么少的裝配,不應該有任何沖突的裝載。 我還將FluentValidation衛星程序集移開了,但仍然得到了異常。
好的,我知道了。 首先,我要感謝Jeremy Skinner 與我一起重現這個問題。 他的幫助促使我嘗試進一步調整我的環境。
要防止出現此問題,您必須在Visual Studio 2010 Ultimate中禁用IntelliTrace ,或者必須將FluentValidation添加到IntelliTrace應從收集數據中排除的模塊列表中。 我的網絡搜索似乎表明它是一個IntelliTrace錯誤。 Jim Nakashima在他的博客文章中說:
問題是IntelliTrace本身有一個錯誤,當IntelliTrace集合設置為“高”(這是Cloud IntelliTrace場景中的默認值)時,標記為SecurityTransparent的程序集中具有boolean out參數的方法將失敗。
如果您的方法的簽名包含布爾輸出參數並且您已將程序集安全性設置為SecurityTransparent,您將在自己的代碼中看到這一點。
我查看了我的堆棧跟蹤並簡要介紹了FluentValidation源代碼,但沒有看到這一點。 我懷疑它可能是與LINQ表達式相關的類似IntelliTrace檢測錯誤。
無論如何,這是如何解決問題:
我遇到了同樣的問題,發現TypeMock 6.0是罪魁禍首。 通過禁用TypeMock Isolator(菜單TypeMock - >禁用TypeMock Isolator)我擺脫了問題。 這當然會破壞任何與TypeMock相關的測試。
請注意,當TypeMock出現問題時,將FluentValidation添加到IntelliTrace異常並不能解決問題。
在我的情況下,我的Asp.net MVC 3應用程序引用了FluentValidation.dll和FluentValidation.mvc.dll文件。
我刪除了引用並使用nuget包管理器安裝了FluentValidation for MVC 3並且它工作正常。
它下載了FluentValidation.Mvc版本5.0.0.1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.