Skip to content

Consider invalidating ComponentProperties cache when Hot Reload triggers metadata update #43780

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

Open
tmat opened this issue Sep 6, 2022 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-hot-reload This issue is related to the Hot Reload feaature Pillar: Dev Experience Priority:0 Work that we can't release without
Milestone

Comments

@tmat
Copy link
Member

tmat commented Sep 6, 2022

Describe the bug

This cache might need to be invalidated after Hot Reload applies a change since it caches information about properties that can change during the update:
https://source.dot.net/#Microsoft.AspNetCore.Components/Reflection/ComponentProperties.cs,18

Related:
https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1601868
dotnet/runtime#75154

@tmat tmat added the feature-hot-reload This issue is related to the Hot Reload feaature label Sep 6, 2022
@tmat
Copy link
Member Author

tmat commented Sep 6, 2022

@mkArtakMSFT

@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Sep 7, 2022
@mkArtakMSFT mkArtakMSFT added this to the .NET 8 Planning milestone Sep 7, 2022
@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Sep 7, 2022
@ghost
Copy link

ghost commented Oct 6, 2023

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.

@tmat
Copy link
Member Author

tmat commented May 27, 2025

@javiercn It seems like there is a code path that should be invalidating the cache on Hot Reload.

However, try the following repro steps:

  1. Unzip Repro.zip and open WebAppCachingType.sln in VS
  2. F5
  3. Exception should be reported:
An unhandled exception occurred while processing the request.
InvalidCastException: Unable to cast object of type 'System.String[]' to type 'System.Collections.Generic.List`1[System.String]'.
Microsoft.AspNetCore.Components.Reflection.PropertySetter.CallPropertySetter<TTarget, TValue>(Action<TTarget, TValue> setter, object target, object value)
  1. Change PhotoList.razor from
public List<string> Photos { get; set; } = [];

to

public IEnumerable<string> Photos { get; set; } = [];
  1. Apply change (Hot Reload)
  2. The exception is still thrown with the old type

The cache doesn't seem to be cleared:

Placing function breakpoint to Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties and stepping shows the cache is not empty

Image

Turns out that OnDeltaApplied event is not subscribed to when Hot Reload happens:

Image

Once this is addressed we might hit dotnet/runtime#75154.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-hot-reload This issue is related to the Hot Reload feaature Pillar: Dev Experience Priority:0 Work that we can't release without
Projects
None yet
Development

No branches or pull requests

5 participants
@tmat @danroth27 @MackinnonBuck @mkArtakMSFT and others