I've noticed that the "Just My Code"/"Break On Unhandled Exeptions" feature of debugging isn't working when dynamically invoking a method using the .net Framework 4.0 or higher. If I change the project to use the 3.5 framework, it runs just fine.
Given this example Command Line App:
using System;
namespace InvokeFail
{
class Program
{
static void Main(string[] args)
{
HandledExceptions();
}
public static void HandledExceptions()
{
try
{
Fail();
}
catch (NotImplementedException)
{
// handle it amazingly well
}
try
{
InvokeFail();
}
catch (NotImplementedException)
{
// handle it amazingly well
}
}
private static void Fail()
{
throw new NotImplementedException();
}
private static void InvokeFail()
{
try
{
typeof(Program).GetMethod("Fail", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
.Invoke(null, null);
}
catch (System.Reflection.TargetInvocationException ex)
{
throw ex.InnerException;
}
}
}
}
And these VS Debug Options:
Here is a picture of where the debugger stops, and it's call stack: