Open
Description
In a .razor
component:
<div style="@null">x</div> <!-- error -->
<div style="@((string?)null)">x</div> <!-- ok -->
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
- Razor compilation fails after upgrading from VS 17.5.x to 17.6.0: warning RZ10012, error RZ9991, error CS1660, error CS1662 #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.
Activity