.NET 8 - Warning AD0001: Analyzer 'Microsoft.AspNetCore.Analyzers.RouteHandlers.RouteHandlerAnalyzer' threw an exception of type 'System.InvalidOperationException'
After upgrading an application to .NET 8, the following warning appeared inside my IDE:
Warning AD0001: Analyzer 'Microsoft.AspNetCore.Analyzers.RouteHandlers.RouteHandlerAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'Failed to resolve well-known type 'Microsoft.AspNetCore.Builde
r.EndpointRouteBuilderExtensions'.'.
As I have the ‘Treat Warnings as Errors’ setting enabled by default, this was a blocking issue for me.
The problem is caused by a Roslyn lookup inside the RouterAnalyzer
which searches for the EndpointRouteBuilderExtensions
class by using GetTypeByMetadataName
. However as HotChocolate is using exactly the same class name and namespace, null is returned instead of the correct type.
This issue not only happens when using HotChocolate but also with the AspNetCore.HealthCheck.UI package that also has an EndpointRouterBuilderExtension class: AspNetCore.Diagnostics.HealthChecks/src/HealthChecks.UI/Extensions/EndpointRouteBuilderExtensions.cs
Of course we could ignore this warning:
But based on the information I found on Github, this should be fixed in the .NET 8.0.1 release.