C# Uncaught exception in unit test

十年热恋 提交于 2019-12-14 03:45:23

问题


I'm encountering a very strange issue while debugging a unit test. If I debug the unit test (ctrl+r ctrl+t) I am getting an uncaught exception. If I just run the unit test (ctrl+r t) I do not get this exception.

The uncaught exception is a NHibernate.ByteCode.ProxyFactoryFactoryNotConfiguredException.

Stack trace:

at NHibernate.Bytecode.AbstractBytecodeProvider.get_ProxyFactoryFactory() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Bytecode\AbstractBytecodeProvider.cs:line 32
at NHibernate.Validator.Util.NHibernateHelper.IsProxyFactoryConfigurated()

I used .Net Reflector to look at the assembly that defines this method (NHibernate.Validator ... it's open source) and here is the method that "throws" the exception:

public static bool IsProxyFactoryConfigurated()
{
    try
    {
        IProxyFactoryFactory proxyFactoryFactory = Environment.BytecodeProvider.ProxyFactoryFactory;
        return true;
    }
    catch (ProxyFactoryFactoryNotConfiguredException)
    {
        return false;
    }
}

How can this exception not be caught by that Try Catch block?


回答1:


It sounds like you're seeing a first chance exception.

Do you have "Break on first-chance exceptions" enabled? You should be able to configure it in the Debug->Exceptions menu.




回答2:


You probably have Break on All Exceptions set in the debugger, which causes VS to break as soon as an exception is thrown, regardless of whether it's caught.
Click Debug, Exceptions.



来源:https://stackoverflow.com/questions/5671917/c-sharp-uncaught-exception-in-unit-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!