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

"Non-static method requires a target" error is thrown when navigating between pages in blazor wasm with lazy loading of assemblies #27637

Closed
Stamo-Gochev opened this issue Nov 9, 2020 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly ✔️ Resolution: Fixed The bug or enhancement requested in this issue has been checked-in!

Comments

@Stamo-Gochev
Copy link

Describe the bug

Using lazy loading of assemblies throws an error when navigating between pages.

Additional context

A blazor wasm project is configured to use lazy loading for a class library project that has some dependencies. The app is inspired by the example from Dan Roth and the MyComponents lib. The Counter.razor page is intentionally implemented to load a separate layout page, so that the required assemblies are loaded only if this page is requested.

To Reproduce

  1. Clone https://github.com/Stamo-Gochev/blazor-wasm-lazy-loading-issue
  2. Set the server project as a startup project
  3. Run the app by pressing Ctrl + F5
  4. Navigate between the "Index" and "Lazy loading" tab a few times.

lazy-loading-renderer-error-components

Note: The exact number of navigations depends on the number of components (lowering the number of components requires more navigation clicks for the error to be thrown). A more real-world scenario might be for a page to contain multiple grid components with a decent number of rows and columns, e.g. 5 grids with 20x20 cells on the same page.

Expected

No error is thrown

Actual

An exception is thrown and the app crashes

Exceptions (if any)

AN exception is thrown in the console

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Non-static method requires a target.
System.Reflection.TargetException: Non-static method requires a target.
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, Object[] parameters, Boolean wrapExceptions)
at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, 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 Microsoft.AspNetCore.Components.DefaultComponentActivator.CreateInstance(Type componentType)
at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateComponent(Type componentType)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame& frame, 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.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, ArrayRange1 newTree)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

Further technical details

  • ASP.NET Core version 5.0 RC2
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) latest
@javiercn javiercn added area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Nov 9, 2020
@captainsafia
Copy link
Member

Are you able to repro this issue in the .NET 5 RTM release?

You can download the nightly at https://github.com/dotnet/installer#installers-and-binaries or install the .NET 5 release tomorrow.

@captainsafia captainsafia added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Nov 9, 2020
@Stamo-Gochev
Copy link
Author

@captainsafia I've updated the project to 5.0.0 and the issue is still reproducible. Note that you might need to make the navigation between pages several times for the error to be thrown.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Nov 13, 2020
@captainsafia
Copy link
Member

@Stamo-Gochev Got it! Thanks for clarifying. In that case, it looks like you are running into a variant of dotnet/runtime#43402. A fix for this will be shipped in the 5.0.100 patch for .NET 5.

@captainsafia captainsafia added ✔️ Resolution: Fixed The bug or enhancement requested in this issue has been checked-in! and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Nov 13, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly ✔️ Resolution: Fixed The bug or enhancement requested in this issue has been checked-in!
Projects
None yet
Development

No branches or pull requests

3 participants