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
- Disable AD0001 as workaround for analyzer bug The current version of .NET 8.0 contains a bug [1] in `RouteHandlerAnalyzer` that causes it to throw `InvalidOperationException` with message 'Failed to ... — committed to smfeest/buttercup by smfeest 3 years ago
- fix issue with name clash between .net and health check package, see https://github.com/dotnet/aspnetcore/issues/50836 — committed to DFE-Digital/fh-service-directory-admin-ui by lazcool 3 years ago
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
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.EndpointRouteBuilderExtensionsstatic 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?
Using HotChocolate, but adding a simple route near the bottom of my file causes this error
Error goes away if that line is commented out
The compilation result is not affected, but the error message is annoying
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:
package AspNetCore.HealthChecks.UI (7.0.2) is also causing this issue to appear