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

Blazor WebAssembly lazy loading assemblies not working when using @ref attribute in the component #29342

Closed
ajithr opened this issue Jan 15, 2021 · 17 comments
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-blazor-builtin-components Features related to the built in components we ship or could ship in the future feature-blazor-lazy-loading Issues related to adding support for lazy-loading in Blazor feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly severity-major This label is used by an internal tool
Milestone

Comments

@ajithr
Copy link

ajithr commented Jan 15, 2021

Describe the bug

  • When using Blazor WebAssembly lazy loading assemblies with component's @ref attribute, the corresponding assembly could not load issue throws in the browser console and the application not running.

To Reproduce

https://github.com/ajithr/blazor-wasm-lazy-ref

  • Check out the above repo and open ~/LazyLoadingRef/LazyLoadingRef.csproj file in the VS 2019.
  • Run the application it will throw exceptions in the browser console.
  • Open ~/LazyLoadingRef/Pages/Counter.razor file and remove @ref attribute and LazyLoadComponent reference in the @code section.
  • Run the sample again and it will work properly with the lazy loading feature.
    image

Exceptions (if any)

image

Further technical details

  • ASP.NET Core version - .net5.0

  • Include the output of dotnet --info
    image

  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
    image

@javiercn javiercn added feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly area-blazor Includes: Blazor, Razor Components labels Jan 15, 2021
@javiercn
Copy link
Member

@ajithr thanks for contacting us.

This seems to be an issue, I can't tell there's anything wrong from looking at the code.

@captainsafia do you have any thoughts?

@ghost
Copy link

ghost commented Mar 16, 2021

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!

@ghost ghost closed this as completed Mar 16, 2021
@ajithr
Copy link
Author

ajithr commented Mar 17, 2021

@mkArtakMSFT @javiercn @captainsafia The issue is closed itself by msftbot. Do we really need to create a new issue report for this? It is not yet discussed and it is under investigation.

@captainsafia
Copy link
Member

@ajithr Thanks for the following up. Reopening this issue and moving to backlog.

I had a hunch that this might be caused by some issues that existed in the codepaths used for assembly loading in the WASM runtime. We'll need to (1) validate if this still happens in .NET 6 and (2) investigate why if it does.

@ghost
Copy link

ghost commented Mar 17, 2021

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@captainsafia captainsafia added affected-few This issue impacts only small number of customers severity-major This label is used by an internal tool labels Mar 17, 2021
@javiercn javiercn added feature-blazor-lazy-loading Issues related to adding support for lazy-loading in Blazor feature-blazor-builtin-components Features related to the built in components we ship or could ship in the future labels Apr 20, 2021
@guardrex
Copy link
Contributor

guardrex commented Jul 8, 2021

@captainsafia ... My error from our offline chat is the same accessing a type in a lazily-loaded RCL assembly. Should I add my error details here or open a new issue?

@captainsafia
Copy link
Member

@guardrex You can add the details here. Both issues might have the same root cause.

@guardrex
Copy link
Contributor

Error:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.
Could not load type of field 'LazyLoadTest.Pages.Robot+RobotModel:k__BackingField' (0) due to: Could not load file or assembly 'GrantImaharaRobotControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

The error isn't thrown when the user tries to navigate to the component: It's thrown at app start up.

The lazily-loaded RCL assembly (GrantImaharaRobotControls.dll) includes:

public enum Axis
{ 
    Left,
    Right,
}

The WASM app seeks to use the type in a component (Pages/Robot.razor in the app) ...

@page "/robot"
@using GrantImaharaRobotControls

...

@code {
    private RobotModel robotModel = new() { AxisSelection = Axis.Left };
    
    ...

    public class RobotModel
    {
        public Axis AxisSelection { get; set; }
    }
}

In App.razor ...

if (args.Path.EndsWith("/robot"))
{
    var assemblies = await AssemblyLoader.LoadAssembliesAsync(new[] { "GrantImaharaRobotControls.dll" });
    lazyLoadedAssemblies.AddRange(assemblies);
}

In the project file ...

<ItemGroup>
  <BlazorWebAssemblyLazyLoad Include="GrantImaharaRobotControls.dll" />
</ItemGroup>

Repro project: https://github.com/guardrex/LazyLoadSolution

To workaround this for the doc, I've simply placed the Robot component into the RCL. It's routable from the app, renders fine, and uses Axis fine in the RCL. We can go with that for the doc. I cross-link to this engineering issue from a remark in the topic. I'll revert/version and/or update the doc remark later. I plan to shoot that PR in shortly ... tomorrow maybe. dotnet/AspNetCore.Docs#22603

@ghost
Copy link

ghost commented Jul 27, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mkArtakMSFT mkArtakMSFT added bug This issue describes a behavior which is not expected - a bug. and removed investigate labels Jul 27, 2021
@Bala-E98
Copy link

Hi Guys,
I'm facing same exceptions. May I know the status of this issue?

@Sureshv2
Copy link

Hi Guys

Because of @ref attribute issue, we cannot use lazy loading assembly feature in our project and it is downloading all referenced assemblies which is not required at initial startup page. Please do let us know that when it could be fixed.

@bingxueyinlian
Copy link

same problem

@syncsiva
Copy link

syncsiva commented Mar 7, 2022

Hi Guys, Any update on this issue. This affects using Lazy loading in blazor WASM apps.

@laurence73
Copy link

same problem

@danroth27 danroth27 modified the milestones: Backlog, .NET 8 Planning Sep 29, 2022
@ghost
Copy link

ghost commented Sep 29, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 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.

@mkArtakMSFT mkArtakMSFT modified the milestones: .NET 8 Planning, Backlog Oct 19, 2022
@ghost
Copy link

ghost commented Oct 19, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@danroth27
Copy link
Member

Both repro projects seem to work fine with .NET 7, so it looks like this issue is now fixed. If you're still hitting this issue, please let us know and provide detailed steps to reproduce the problem and we'll take another look.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-blazor-builtin-components Features related to the built in components we ship or could ship in the future feature-blazor-lazy-loading Issues related to adding support for lazy-loading in Blazor feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly severity-major This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests