Skip to content

Warning AD0001 : Analyzer 'Microsoft.AspNetCore.Analyzers.RouteHandlers.RouteHandlerAnalyzer' NullReferenceException due to dynamic in method signature #61319

Open
@peeveen

Description

@peeveen

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Warning is shown when building a webapp that uses a dynamic parameter in a minimal API endpoint.

AD0001: Analyzer 'Microsoft.AspNetCore.Analyzers.RouteHandlers.RouteHandlerAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.

Expected Behavior

No warning.

Steps To Reproduce

A minimal API webapp, with the following type of endpoint:

endpointRouteBuilder.MapPost("/blah",
    async (
        ... various params ...
        [FromBody] dynamic someOtherThing
    ) => {
        ... do stuff ...
    }
);

The [FromBody] is not really important. Same thing if I remove it.
It seems to be the dynamic parameter that causes it.
I know that using a dynamic here is kinda strange, but I have configured the services (via services.ConfigureHttpJsonOptions) with a custom JSON converter than can convert data to a dynamic.
Weirdly, after seeing this warning, repeating the operation (e.g. dotnet build) completes without the warning. It seems to only occur once immediately after a code change.

Exceptions (if any)

System.NullReferenceException

.NET Version

9.0.202

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    analyzerIndicates an issue which is related to analyzer experiencearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions