`@null` attribute value results in ambiguity
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
In a `.razor` component:
```razor
```
> error CS0121: The call is ambiguous between the following methods or properties: 'RenderTreeBuilder.AddAttribute(int, string, string?)' and 'RenderTreeBuilder.AddAttribute(int, string, MulticastDelegate?)'
Note that passing `null` to an attribute is a supported scenario: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-7.0#conditional-attribute-rendering. Although perhaps it doesn't make much sense to pass a literal `@null` but rather via some variable.
It also works fine in `.cshtml`.
Related:
- https://stackoverflow.com/questions/71415039/blazor-error-the-call-is-ambiguous-between-the-following-methods-or-properties
- https://github.com/dotnet/razor/issues/8731 (mentions the same error but it's otherwise unrelated to that issue)
I think compiler cannot do much here, we don't analyze the user-written C# code. At most we could offer an analyzer to fix this by casting.
Contributor guide
Assessment
This issue has not been assessed yet.