Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert faild exception was not handled in user code

when I made an unit test and there is an exception as below, can any one tell me what's wrong with this:

An exception of type 'Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException' occurred in Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll but was not handled in user code

like image 283
Foster Hao Avatar asked Dec 25 '22 18:12

Foster Hao


1 Answers

I had this problem in Visual Studio 2012. Here's how I fixed it:

In the exception pop up, I had a checked box next to "Break when this type of exception isn't user-handled."

I unchecked the box.

Sometimes it's the simple things that get you. :)


Update 1 year later :)

So this doesn't pertain to this particular question, but I learned another trick to hide exceptions that are thrown by non-Microsoft .dll's. (Assert.Failed is inside one of the System libraries, so the OP wouldn't need to use this trick.)

You may have noticed that some exceptions mysteriously continue to break when unhandled, even when you uncheck the "Break when this exception type is thrown" box.

There is a reason for this! Visual Studio doesn't know how to recognize that Exception type.

Here's how to teach it a new trick:

  1. Get the full exception name, with all of its namespacing. For example, you'll need "MySql.Data.MySqlClient.MySqlException", not just "MySqlException". Click "View Detail" in the exception popup to get this information.
  2. Go to the DEBUG menu -> Exceptions.
  3. Click the "Add...." button.
  4. In the popup that appears, pick a sub-grouping that you'd like to add your new exception to. For MySql, I used "Common Language Runtime Exceptions", but pick whichever group makes sense to you. I don't believe you can add your own, unfortunately.
  5. For the exception name, enter the fully qualified exception name that you found in step 1.
  6. Save, and then uncheck the "Thrown" box for your shiny new exception!

Once you've added your exception, you'll also be able to use the "Break when this exception is thrown" checkbox in the popup again.

Happy coding!

like image 94
SMiller Avatar answered Dec 28 '22 11:12

SMiller