So I found a solution that works in VS 2019, it is a bit more complicated than I would like but for my use case it was necessary to solve this problem.
Instructions
First move the code that is causing the issue to its own function so you are not suppressing exceptions in surrounding code, and mark it with the DebuggerStepThrough attribute (or DebuggerHidden works too).
[DebuggerStepThrough]
public void ExceptionThrowingFunction()
{
//.. Code that throws exception here
}
Then call it like this
OutsourceException(ExceptionThrowingFunction);
Then take either a separate project (module) that either you don't care about suppressing all exceptions in, or that is specifically created for this purpose. It is important that this is a separate project so that your main project can still break on this exception type. In my case I already had a small util project called SharedFunctions so I put it there. The code is pretty stable and does not need debugging most of the time.
In a class called ExceptionUtils I added the following functions:
public static T OutsourceException<T>(Func<T> func)
{
T result = default;
try
{
result = func.Invoke();
}
catch { }
return result;
}
public static T OutsourceException<T, Y>(Func<T, Y> func, Y arg)
{
T result = default;
try
{
result = func.Invoke(arg);
}
catch { }
return result;
}
public static void OutsourceException<T>(Action<T> action, T arg)
{
try
{
action.Invoke(arg);
}
catch { }
}
You may need to add more of these, these cover just the basic cases where you have 0-1 arguments in your function.
Finally, when you run the code, it will still break on the exception in the Outsource function with a message like this:
If you check the bottom checkbox (in this example 'SharedFunctions.dll') it will add a rule that the exception should be ignored if thrown from that assembly. Once this is checked the exception should be suppressed. All other exceptions in the main assembly of this type will still break as normal.
What is happening here?
Due to the changes in VS 2015 that broke the [DebuggerHidden] and similar attributes (see the blog post linked in another answer here) the attributes now pass the exception to the calling class and the debugger simply breaks there. The if we move the calling class into another assembly we can suppress the exception using the exception conditions system.
Why not just fix the exception?
Some exceptions can't be removed from the code completely, for example when you try to access Package.Current
in a UWP application. It will always throw an exception in the debugger, and this can only be resolved by microsoft. Another solution in this case is to just surround it with #if !DEBUG
but there are other cases where this is not practical.