How to debug System.ArgumentException in Output window? - visual-studio

I'm using .NET Core 2.2 with EF and when queries are being run against database, I see a bunch of ArgumentExceptions being logged in the Output -> Debug window such as:
Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll
The thing is my app is working perfectly fine, I get proper results and everything. I see like a hundred of these in the Visual studio's debug for no apparent reason.
Is there anyway I could find more information about these exceptions? Maybe let Visual studio break on them or something like that?
Edit: This did not happen on a different machine. I guess something bad is happening with my system and I could not tell what.

So, the answer is to enable System.ArgumentException at Visual Studio setting Debug -> Windows -> Exception Settings->Common Language Runtime Exceptions.

Related

Exceptions not thrown in web api

I'm using Web Api and when an exception happens in my code (for example a bad cast), and the debugger is attached, the exception is not thrown in Visual Studio. I just get the 500 internal server error on the browser side with the exception details but it's a pain because I have to track down what line it's thrown on.
I don't believe this was always the case, and thought it must be one of my settings messed up but I have already tried to reset visual studio settings to no avail.
How can I get the debugger to break again on 500 internal server errors.. I don't want to enable first chance exceptions.
Tools -> Options -> Debugging -> General, Ensure that "Enable Just My Code" is checked.
In visual studio Debug->Exceptions for exceptions that you need or for all of them select checkbox in the Throw column. It's because by default Asp.Net runtime handles all exceptions. MSDN

Visual Studio Error display

How can the errors in Visual Studio be displayed as in this image:
instead of using the Error List?
The exceptions I get are displayed like this:
(The images are from: How to tell the debugger to ignore breaking on thrown exceptions?, Where did my Visual Studio exception assistant go?)
If you look under Tools | Options in the Debugging | General node, be sure your "Enable the Exception Assistant" is checked.
The error message that is displayed in the first picture is a message displayed for .Net exceptions. (Anything that inherits from System.Exception)
The .Net exception class has members that include data and stack trace that can be displayed nicely and the Visual Studio IDE displayes it for you.
Native errors (from native code or windows code, anything not .Net) is displayed with the second window.
Native exceptions to contain a minimal what() string. Sometimes. But any other class type can be thrown too, so there's not always that much information.

A first chance exception of type 'StructureMap.StructureMapException' occurred in StructureMap.DLL

Hello I'm getting this exception thrown at me whenever I try to test a web application via visual studio, any ideas why? I'm building a project using MVC3 model and visual studio 2010
Exception: A first chance exception of type 'StructureMap.StructureMapException' occurred in StructureMap.DLL
First chance exceptions might occur while debugging. They might be handled properly by your code and never propagate when running the application normally but nevertheless Visual Studio shows them in Debug mode. If you don't want to be bothered you could disable them in Visual Studio and they will no longer appear.

Program won't start unless debugging

I have a program I made using Visual Studio that won't start unless VS is debugging. Where should I look for problems?
The program works when debugging through VS but won't start from the debug folder. The program works fine when debugging. No output is given.
For this sort of startup problem I'd suggest running your app in Windbg (part of the Debugging Tools for Windows). Do File -> Attach to executable and then hit F5. You should get more informative output there. I suspect it's a dll dependency or manifest problem. Another useful tool is the Dependency Walker which may highlight some dlls that are on Visual Studio's path but not your default path, which may also explain the error. Another thing to try is check that all types of debug output are being shown in Visual Studio: right-click to get the context menu in the debug output window and ensure it's showing exception messages and module load messages.
Try turning on Stop on Exceptions
Debug - Exceptions - Common Language Runtime Exceptions (thrown and user unhandled)

Visual Studio Just-In-Time Debugging Annoyances

I have a solution comprising of about 6 projects, and when I debug on one machine, any un-handled exceptions that occur cause the environment to break at the point that exception is thrown, allowing me to debug it.
However, on a different machine with the same solution (in the same version of VS), all I get when an exception is thrown is the "Visual Studio Just-In-Time debugging" window popping up, which tells me the name of the exception, and little else - it offers to open a new visual studio instance in order to debug it, but that doesn't work, because it is already being debugged by the IDE!
What is going on, and how can I get back to visual studio telling me where the exception happened?
Cheers
You might want to check Exceptions in the Debug menu (mapped by default to Ctrl+Alt+E) and verify that both machines have the same exceptions selected.
Probably on the second machine you have less exception types selected in that window. When one of the exceptions that are not selected is thrown:
the debugger does not handle it because it has been instructed not to
the exception gets passes to the OS
the OS launches the default system-wide debugger which is the "Visual Studio Just-In-Time debugging" launcher if you installed VS2005 on that machine.
Sounds like it can't find the debug info.
Try copying the PDB files to your output directory.
I've had this problem as well - two machines, identical exception settings, different behaviours. The solution for me was to set the Debugger Type in the project properties on the "bad" machine to Mixed, even though the application only contains managed code. On the "good" machine exceptions are caught in Visual Studio using the Managed Only setting.

Resources