Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.net8+orchardcore blazorserver mode render component error #15211

Closed
justlucky opened this issue Jan 31, 2024 · 2 comments · Fixed by #15247
Closed

.net8+orchardcore blazorserver mode render component error #15211

justlucky opened this issue Jan 31, 2024 · 2 comments · Fixed by #15247
Labels

Comments

@justlucky
Copy link

Describe the bug

.net8+orchardcore create webpage, use blazorserver mode @(await Html.RenderComponentAsync(RenderMode.ServerPrerendered)) error.

error content:
System.InvalidOperationException: The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.

To Reproduce

Steps to reproduce the behavior:

  1. Create a OrchardCore app, add module, and add WebPage page.
  2. Create blazorclasslibrary project, add default Component.
  3. call Html.RenderComponentAsync in webpage.
  4. browser webpage.

Expected behavior

System.InvalidOperationException: The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.

Screenshots

a1
a2

@ns8482e
Copy link
Contributor

ns8482e commented Jan 31, 2024

That's default behavior of Razor Component rendering!!! According to Microsoft's docs

Any calls to RenderComponentAsync must be made in the context of calling InvokeAsync on a component dispatcher.

https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-components-outside-of-aspnetcore?view=aspnetcore-8.0

To render component from .cshtml you can use tag helper

<component type="typeof(Component1)" render-mode="ServerPrerendered" />

@justlucky
Copy link
Author

justlucky commented Feb 2, 2024

这是 Razor 组件呈现的默认行为!!根据 Microsoft 的文档

对 RenderComponentAsync 的任何调用都必须在对组件调度程序调用 InvokeAsync 的上下文中进行。

https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-components-outside-of-aspnetcore?view=aspnetcore-8.0

要渲染组件,您可以使用标记助手.cshtml

<component type="typeof(Component1)" render-mode="ServerPrerendered" />

. net7 is normal,. net8 is incorrect, the environment is .net8+orcardcore, not console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants