RouteHandlerAnalyzer throws IndexOutOfRangeException (AD0001) when the route handler is a method group from a referenced assembly
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
# RouteHandlerAnalyzer throws IndexOutOfRangeException (AD0001) when the route handler is a method group from a referenced assembly
### Is there an existing issue for this?
Searched open and closed issues for `RouteHandlerAnalyzer` + `AD0001` / `IndexOutOfRangeException`; found nothing matching this trigger.
### Describe the bug
`Microsoft.AspNetCore.Analyzers.RouteHandlers.RouteHandlerAnalyzer` throws
`System.IndexOutOfRangeException` and is disabled for the rest of the compilation
whenever a minimal API route handler is passed as a **method group defined in a
referenced assembly**.
The compiler reports this as `AD0001`, which is a warning by default — so most
projects never notice, they just silently lose route-handler diagnostics
(RDG/ASP-prefixed analyzers) for that compilation.
Projects that build with `true`
(common in regulated environments and in CI templates) fail the build outright.
The exception does **not** occur when the identical handler is declared in the
same assembly, which points at cross-assembly symbol resolution inside the
analyzer rather than at the handler signature.
### Expected behavior
The analyzer completes without throwing, and route-handler diagnostics keep
working, regardless of which assembly the handler method is declared in.
### Steps to reproduce
Two projects, four files, no packages beyond the shared framework.
**`Lib/Lib.csproj`**
```xml
net10.0
enable
enable
```
**`Lib/Handlers.cs`**
```csharp
using Microsoft.AspNetCore.Http;
namespace Lib;
public static class Handlers
{
public static IResult GetById(string id) => Results.Ok(id);
}
```
**`Web/Web.csproj`**
```xml
net10.0
enable
enable
```
**`Web/Program.cs`**
```csharp
using Lib;
var app = WebApplication.Create();
// Handler is a method group defined in a referenced assembly.
app.MapGet("/items/{id}", Handlers.GetById);
app.Run();
```
Then:
```
dotnet build Web/Web.csproj
```
To see it as a build failure rather than a warning, add
`true` to `Web/Web.csproj`.
### Actual behavior
```
CSC : warning AD0001: Analyzer 'Microsoft.AspNetCore.Analyzers.RouteHandlers.RouteHandlerAnalyzer'
threw an exception of type 'System.IndexOutOfRangeException' with message
'Index was outside the bounds of the array.'.
```
With `true` the same message is
emitted as `error AD0001` and the build fails.
### Variations tried
| Variation | Throws? |
|---|---|
| Handler is a method group in a **referenced assembly** | **yes** |
| Same handler declared in the **same assembly** | no |
| `MapGet` with a route parameter (`/items/{id}`) | yes |
| `MapPost` with only a complex body parameter | yes |
| Lambda instead of a method group | no |
So the trigger is the referenced-assembly method group, not the parameter shape
or the HTTP method.
### Regression?
Not verified against earlier versions.
### Known workarounds
- Declare a thin wrapper method in the web project and pass that instead.
- Use a lambda that calls into the referenced assembly.
- Suppress with `$(NoWarn);AD0001` — but this silences *all*
analyzer crashes in the project, not just this one.
### .NET version
Reproduces on both:
- `10.0.300`
- `11.0.100-preview.4.26230.115`
Host: macOS (darwin arm64).
Contributor guide
Research direction
Start by reproducing the failure with the four mentioned files and `dotnet build Web/Web.csproj`, then inspect the `Microsoft.AspNetCore.Analyzers.RouteHandlers.RouteHandlerAnalyzer` entry point. Compare the referenced-assembly method-group case with the same-assembly and lambda variations; done means the build emits no AD0001 and route-handler diagnostics continue working.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100