question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Experiencing "Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to MyComponent"

See original GitHub issue

@jjonescz @danroth27

I 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:closed
  • Created 2 months ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MarkStegacommented, Jul 12, 2023

@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.

1reaction
MarkStegacommented, Jul 12, 2023

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

error CS0029: Cannot implicitly convert type 'Microsoft. ...
I get this error: " error CS0029: Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to MyComponent only when ...
Read more >
Blazor error: Cannot implicitly convert type 'Microsoft. ...
microsoft. Application is blazor and I get error: Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to ...
Read more >
Error CS0029: Cannot implicitly convert type 'Microsoft. ...
Error CS0029: Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' after update to 17.6Closed - Fixed
Read more >
Window for Blazor - Preventing window from opening off ...
Regarding the Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to 'DevExpress.Blazor.
Read more >
ASP.NET Core Razor components
Learn how to create and use Razor components in Blazor apps, including guidance on Razor syntax, component naming, namespaces, and component ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found