aspnetcore: [8.0] RouteHandlerAnalyzer throws InvalidOperationException

I’ve hit the following error while working on https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/pull/2044.

CSC : error 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'.'. 
PS D:\projects\forks\healthChecks> dotnet --info
.NET SDK:
 Version:   8.0.100-rc.2.23429.6
 Commit:    4bafa2271a

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100-rc.2.23429.6\

Repro:

git clone https://github.com/adamsitnik/AspNetCore.Diagnostics.HealthChecks.git --branch reproBug reproBug
cd reproBug
dotnet build .\test\HealthChecks.UI.Tests\HealthChecks.UI.Tests.csproj

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 23
  • Comments: 20 (9 by maintainers)

Commits related to this issue

Most upvoted comments

This is also affecting HotChocolate.

To follow-up on this, the fix for this has been merged and is expected to be released in the next servicing release of .NET 8. In the meantime, recommend using the workarounds mentioned above.

Hi everyone – the bug fix has been released as part of today’s (January 9th) monthly release. You can download it at https://dotnet.microsoft.com/en-us/download/dotnet/8.0. Let me know if there are any other issues!

@michaelmcneilnet

Is there any workaround for this?

<PropertyGroup>
  <NoWarn>$(NoWarn);AD0001</NoWarn>
</PropertyGroup>

Thanks for the feedback here folks! The actual fix to this issue is in https://github.com/dotnet/aspnetcore/pull/50969. I’m bumped CI and request for reviews on this PR so that we can get it in the next servicing cycle.

In the meantime, the workarounds identified in this comment should be sufficient for projects running into this with the dependencies at hand.

For context, this issue will manifest if any library references in your application are also declaring methods in the Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions static class. In this case, Roslyn’s lookup will throw an exception when it discovers two types of the same name when resolving type symbols by name from metadata.

The fix here was to modify the behavior of our lookup to use alternative APIs that only checked for types based on name and assembly.

Thanks for reporting this issue, @adamsitnik! We’ve gotten a few similar reports over the past few days including in https://github.com/dotnet/aspnetcore/issues/50868 and https://github.com/dotnet/aspnetcore/issues/50881. I’ll close those in favor of using this one as the investigation.

https://github.com/dotnet/aspnetcore/issues/50868 highlights the framework reference being included as possibly related but I think that there might be a red herring considering the nature of the other bug reports. I’ll dig in and see what I can find…I suspect upgrading runtime versions ithe more likely dilemma here…

I am facing the same issues when I use AspNetCore.HealthChecks.UI (version 7.0.2)

I get 3 similar warnings in 3 different analyzers… (I’m using HotChocolate also)

warning AD0001: Analyzer ‘Microsoft.AspNetCore.Analyzers.WebApplicationBuilder.WebApplicationBuilderAnalyzer’ threw an exception of type ‘System.InvalidOperationException’ with message 'Failed to resolve well-known type ‘Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions’

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.Builder.EndpointRouteBuilderExtensions’.’

warning AD0001: Analyzer ‘Microsoft.AspNetCore.Analyzers.RouteEmbeddedLanguage.RoutePatternAnalyzer’ threw an exception of type ‘System.InvalidOperationException’ with message 'Failed to resolve well-known type ‘Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions’

Anyone else seeing this?

Request textDocument/semanticTokens/range failed. Message: Failed to resolve well-known type ‘Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions’. Code: -32000

Using HotChocolate, but adding a simple route near the bottom of my file causes this error

app.MapGet("/graphql/getdocument", () => Results.Ok("hi"));

image

Error goes away if that line is commented out

1>CSC : warning AD0001: 分析器“Microsoft.AspNetCore.Analyzers.RouteHandlers.RouteHandlerAnalyzer”引发类型为“System.InvalidOperationException”的异常,并显示消息“Failed to resolve well-known type 'Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions'.”。

The compilation result is not affected, but the error message is annoying

@michaelmcneilnet

Is there any workaround for this?

<PropertyGroup>
  <NoWarn>$(NoWarn);AD0001</NoWarn>
</PropertyGroup>

Thanks! This set me on the correct path, but in my case I had to do

<NoWarn>$(NoWarn);ASP0003;ASP0004;ASP0005;ASP0007;ASP0020;ASP0021;ASP0022;ASP0024</NoWarn>

This list showed up in one of the errors:

image

package AspNetCore.HealthChecks.UI (7.0.2) is also causing this issue to appear