Wrong inferred type param when passing this
to Microsoft.JSInterop.DotNetObjectRef
#12446
Labels
area-blazor
Includes: Blazor, Razor Components
✔️ Resolution: Duplicate
Resolved as a duplicate of another issue
Preview 6 replaces
DotNetObjectRef
with a genericDotNetObjectRef<T>
. Instead of a constructor, theCreate<T>
method is now used.When passing
this
from within a component, this leads to unexpected results due to Razor's parsing behavior.To Reproduce
Steps to reproduce the behavior:
@code
section:Expected behavior
This should compile. The type parameter of
Create<T>
should be inferred asMySampleComponent
.Actual behavior
This doesn't work, because Razor internally renames your class to
__generated__MySampleComponent
. Consequently, the Error List will show:If you explicitly specify the type parameter, the error changes to CS1503.
Workaround
You can declare the variable with the generated class name:
However, this is presumably not the intended behavior.
The text was updated successfully, but these errors were encountered: