C # exception thrown in unit test

I am having a very strange problem while debugging unit test. If I debug the unit test (ctrl + r ctrl + t), I get an uncaught exception. If I just ran unit test (ctrl + rt), I do not get this exception.

The uncaught exception is 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 view the assembly that defines this method (NHibernate.Validator ... open source), and here is the method that throws an 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 this Try Catch block?

+6
source share
2 answers

It looks like you are seeing the first random exception .

Do you have the option to "Unlock exceptions with a first chance"? You can configure it in the menu "Debug-> Exceptions".

+3
source

You probably have Break on All Exceptions installed in the debugger, which causes the VS to be interrupted as soon as an exception is thrown, regardless of whether it was detected.
Click "Debug", "Exceptions".

+2
source

Source: https://habr.com/ru/post/885952/


All Articles