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

Support components with no parameterless constructor #5875

Closed
pvanroos opened this issue Dec 2, 2024 · 4 comments
Closed

Support components with no parameterless constructor #5875

pvanroos opened this issue Dec 2, 2024 · 4 comments
Labels
Status: Repro Missing Type: Feature ⚙ Request or idea for a new feature.
Milestone

Comments

@pvanroos
Copy link

pvanroos commented Dec 2, 2024

Is your feature request related to a problem? Please describe.

With .NET 9, you can now inject objects into component constructors, obviating the need for [Inject] attribute.

When adding Blazorise to a project, all components that lack a parameterless constructor will throw an exception.

Describe the solution you'd like

Blazorise will not throw an exception that complains that the component lacks a parameterless constructor.

Here is an example of the exception:

blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: No parameterless constructor defined for type '[redacted]'.
System.MissingMethodException: No parameterless constructor defined for type '[redacted].DisplayDetailPage'.
at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Blazorise.ComponentActivator.CreateInstance(Type componentType)
at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType, IComponentRenderMode callerSpecifiedRenderMode, Nullable1 parentComponentId) at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame[] frames, Int32 frameIndex, Int32 parentComponentId) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange1 oldTree, ArrayRange`1 newTree)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

Copy link
Contributor

github-actions bot commented Dec 3, 2024

Hello @pvanroos, thank you for your submission. The issue was labeled "Status: Repro Missing" because you have not provided a way to reproduce the issue quickly. Most problems can be solved when isolated, but we would like you to provide a reproducible code sample to help us investigate a possible bug more effectively.
For your convenience, you can use our pre-configured Bug Report Template repositories to quickly set up a reproducible environment.
Once you've provided a minimal reproduction, we can proceed with the investigation. Thank you for helping us improve Blazorise!

@stsrki
Copy link
Collaborator

stsrki commented Dec 3, 2024

I'm not sure if this is Blazorise problem. All our WASM, and Server apps are converted to .NET9 and are working just fine.

Can you create a repro project for us to test?

@pvanroos
Copy link
Author

pvanroos commented Dec 3, 2024

Yea, sorry. Here you go:

https://github.com/pvanroos/BlazoriseTest-5875

Build and run the project. Then open the / (home) page and view the browser console to see the error.

@stsrki stsrki added this to the 1.7 support milestone Dec 4, 2024
@stsrki stsrki added this to Support Dec 4, 2024
@github-project-automation github-project-automation bot moved this to 🔙 Backlog in Support Dec 4, 2024
@stsrki stsrki closed this as completed Dec 4, 2024
@github-project-automation github-project-automation bot moved this from 🔙 Backlog to ✔ Done in Support Dec 4, 2024
@stsrki
Copy link
Collaborator

stsrki commented Dec 11, 2024

Just a heads-up. The new version is released and we now support this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Repro Missing Type: Feature ⚙ Request or idea for a new feature.
Projects
Status: ✔ Done
Development

No branches or pull requests

2 participants