Experiencing "Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to MyComponent"
See original GitHub issueI ran into the issue reported in #8761 which was closed with a reference to issue (#8718) which was closed as complete.
I was using the 8.0.preview.5 SDK. I followed the table reference for 8.0.100-preview.6.23330.14 SDK, installed, and still have the error.
In my component MOIPrimaryTreatment.Razor I have another component defined as:
<TreatmentDialog pTreatmentDialogCompleted="@TreatmentDialogCompletionAsync"
@ref="pTreatmentDialogRef" />
Instead of having a component defined in the corresponding razor.g.cs I have an element:
__builder.OpenElement(21, "TreatmentDialog");
__builder.AddAttribute(22, "pTreatmentDialogCompleted",
#nullable restore
#line 28 "C:\Solutions\OHI\Optimiser.2021\Optimiser.Client\Views\Dashboard\Processes\Oncology\Segments\Infusion\Helpers\MOIPrimaryTreatment.razor"
TreatmentDialogCompletionAsync
#line default
#line hidden
#nullable disable
);
__builder.AddElementReferenceCapture(23, (__value) => {
#nullable restore
#line 29 "C:\Solutions\OHI\Optimiser.2021\Optimiser.Client\Views\Dashboard\Processes\Oncology\Segments\Infusion\Helpers\MOIPrimaryTreatment.razor"
pTreatmentDialogRef = __value;
#line default
#line hidden
#nullable disable
}
);
__builder.CloseElement();
And then, of course, when I try to use the component reference I get the “Cannot implicitly convert type ‘Microsoft.AspNetCore.Components.ElementReference’ to TreatmentDialog”
Other similar embedded components are working as expected. I just don’t see the code pattern that is causing the generation to fail.
[Edit] I also tried sdk 7.0.400-preview.23356.7 and have the same error…
Issue Analytics
- State:
- Created 2 months ago
- Comments:12 (4 by maintainers)
@ScarletKuro See above for the root cause. The uneven support for long file names in VS is an issue but not the problem this time. I can’t open the generated files with VS due to the path being too long so I have to copy them to a shorter path.
@jjonescz
Thanks for finding that – It is a very annoying Visual Studio ‘side effect’ to put the ‘’'<Content remove``` items if you copy/rename files. It does so silently. I have often copied an existing component in VS, pasted it, renamed the “- Copy”.
I am going to post this in VS feedback as a bug unless you think this is a good behavior on the part of VS.