Steve
Steve

Reputation: 819

C# How to investigate: An unhandled exception was thrown by the application

I am getting the following error in my ASP.NET Core logs:

Microsoft.AspNetCore.Server.Kestrel | Connection id "XXXXX", Request id "YYYY:0000": An unhandled exception was thrown by the application.

Struggling to see how to investigate this further - how can I track down what is causing this? Is there any additional logging I can enable?

Upvotes: 5

Views: 5610

Answers (4)

Timothy Odhiambo
Timothy Odhiambo

Reputation: 45

If you check the Event Viewer under Windows Logs >> Application. Around the same time the exception was thrown, you should see it caught there.

Upvotes: 1

Eduardo Rauchbach
Eduardo Rauchbach

Reputation: 427

You can try using the ILogger from the Microsoft.Extensions.Logging, using the LogError Method

You will need to set the Log to output where you prefer, in the link bellow you can see the basic settings.

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-7.0

In addition, if possible to debug, you can just enable more Exception setting while debugging.

At the bottom of the Visual Studio, this tab will appear, just enabled more options until a more specific exception appears.

enter image description here

Upvotes: 0

Thom Kiesewetter
Thom Kiesewetter

Reputation: 7314

You can't catch this exception it is just logged. See for example source code. In vs you can set a functional breakpoint and load the symbols where needed. Then you can set more breakpoints where needed.

enter image description here

Upvotes: 0

cITsecure
cITsecure

Reputation: 164

You will need to decorate your code with try/catch:

try
{
    //code logic goes here
}
catch(Exception ex)
{
    //handle exception here
    //ex.Message - this will give you string description of the exception
    //ex.InnerException - this will provide you more details when you debug 
    //and have a break point in the exception section then you can view 
    //more details on the exception
}

I hope this helps.

Upvotes: 2

Related Questions