dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.57k stars 10.05k forks source link

Using @ref and @rendermode on the same call site produces an unhelpful error message #51151

Open hannespreishuber opened 1 year ago

hannespreishuber commented 1 year ago

Is there an existing issue for this?

Describe the bug

Just done a simple test to get how the things are working

new template

[Parameter]
 public int MyProperty { get; set; }

 private void IncrementCount()
 {
     currentCount++;
     MyProperty = currentCount;

and

<BlazorApp8.Client.Pages.Counter @ref="Counter1" />
@Counter1?.MyProperty

@code{
    BlazorApp8.Client.Pages.Counter Counter1;
}

Expected Behavior

see the counter value

my intention was to use server side and embed a WASM part and how to communicate between the components

Steps To Reproduce

No response

Exceptions (if any)

System.InvalidCastException: Unable to cast object of type 'Microsoft.AspNetCore.Components.Endpoints.SSRRenderModeBoundary' to type 'BlazorApp8.Client.Pages.Counter'.

.NET Version

8.0.100-rc.1.23455.8

Anything else?

No response

marinasundstrom commented 1 year ago

The component in render mode WebAssembly is not instantiated on the server. Hence the error when trying to catch a component reference - it is a placeholder object. (Added)

The server has no knowledge about the actual state of the component running in the browser with WebAssembly.

For them both to know about each other would require a connection between Server and Client.

You can however communicate between components that are in the WebAssembly context since they , usually, are in the same app. (Added)

mkArtakMSFT commented 1 year ago

Thanks for contacting us. @marinasundstrom is right about the communication aspect of this bug. We are, however, going to keep this issue as a bug to track improving the error message so that it's easier to understand what's happening.

ghost commented 1 year ago

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

marinasundstrom commented 1 year ago

I have added some details to my response. Further explaining the reason for the error.

I agree that the error message can be improved.

hannespreishuber commented 1 year ago

this is just the using effect. I was expecting a failure. But what happens about Autorendermode with statemanagment or parameter accross WASM/Server borders. There is no approach for that!?

ghost commented 11 months ago

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

danroth27 commented 10 months ago

@mkArtakMSFT Does this issue need to move to dotnet/razor?