c#asp.net.netasp.net-coreexceptionhandler

Reference to IExceptionHandler interface not being resolved from Microsoft.AspNetCore.Diagnostics


I am adding a global exception handling project to my solution and have installed the Microsoft.AspNetCore.Diagnostics NuGet package. Although the package is recognized and listed in the project's dependencies, I encounter an error when trying to use the IExceptionHandler interface. The error message is:

CS0234: The type or namespace name 'IExceptionHandler' does not exist in the namespace 'Microsoft.AspNetCore.Diagnostics' (are you missing an assembly reference?)

I am sharing this because similar issues on StackOverflow don’t address problems specific to the Microsoft.AspNetCore.Diagnostics package. Other references, like Microsoft.AspNetCore.Mvc and System.Data.SqlClient, resolve fine for my project. An older but similar issue was posted here. However, it does not exactly match my scenario.

Here are a few observations:


Solution


Adding the following code in my .csproj file resolved the issue:

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />

I'd appreciate it if someone could explain what was wrong and how this fix resolved the issue.