Skip to content

Use MetadataUpdateHandlerAttribute in Blazor #31817

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

Merged
3 commits merged into from
Apr 16, 2021
Merged

Conversation

pranavkm
Copy link
Contributor

  • Annotate HotReloadManager to use the new attribute
  • Add support for invoking the new attribute in WASM's hot reload

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Apr 14, 2021
@pranavkm
Copy link
Contributor Author

pranavkm commented Apr 14, 2021

Ignore this. Our targets had a bug


@Eilon I'm seeing an error building the Wpf app that suggests it's using an older targeting pack:

D:\temp\aspnetcore\.dotnet\sdk\6.0.100-preview.3.21168.19\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets(222,9): error MC1000: Unknown build error, 'Could not find type 'System.Reflection.Metadata.MetadataUpdateHandlerAttribute' in assembly 'D:\temp\aspnetcore\.dotnet\packs\Microsoft.NETCore.App.Ref\6.0.0-preview.3.21167.1\ref\net6.0\System.Runtime.Loader.dll'.'  [D:\temp\aspnetcore\src\Components\WebView\Samples\BlazorWpfApp\BlazorWpfApp.csproj]

Just making sure it's not intentionally pointing to an older version.

@pranavkm
Copy link
Contributor Author

FYI @stephentoub

@pranavkm pranavkm marked this pull request as ready for review April 15, 2021 00:09
@pranavkm pranavkm requested review from a team as code owners April 15, 2021 00:09
@pranavkm pranavkm requested a review from stephentoub April 15, 2021 00:09
@pranavkm pranavkm added this to the 6.0-preview4 milestone Apr 15, 2021
@@ -4,7 +4,7 @@
<!-- Reference base shared framework at incoming dependency flow version, not bundled sdk version. -->
<FrameworkReference
Update="Microsoft.NETCore.App"
Condition=" '$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)' AND '$(TargetLatestDotNetRuntime)' != 'false' "
Condition=" (('$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)') OR ('$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)-windows')) AND '$(TargetLatestDotNetRuntime)' != 'false' "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change related to #31817 (comment)? Maybe add a comment to clarify it here...

_handlerActions ??= GetMetadataUpdateHandlerActions();
var (beforeUpdates, afterUpdates) = _handlerActions.Value;

beforeUpdates.ForEach(a => a(null));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if I understand correctly beforeUpdates and afterUpdates are handlers that can be invoked before and after deltas are applied. What are some scenarios where they are used?

Also -- why does this take a null value instead of just being a parameterless method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are some scenarios where they are used?

e.g. to clear corelib's reflection cache, to clear JsonSerializer's cache of reflection data, to refresh a binding in a UI, etc.

why does this take a null value instead of just being a parameterless method?

The plan is for the agent to pass an array of the types being updated, if available, but we don't have that information yet. The pattern will likely evolve over the next few months as we find out more about what various handlers need.

* Annotate HotReloadManager to use the new attribute
* Add support for invoking the new attribute in WASM's hot reload
@pranavkm pranavkm force-pushed the prkrishn/metadataattribute branch from 836ed82 to 3f7e920 Compare April 15, 2021 13:09
@ghost
Copy link

ghost commented Apr 16, 2021

Hello @pranavkm!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 285d857 into main Apr 16, 2021
@ghost ghost deleted the prkrishn/metadataattribute branch April 16, 2021 19:58
@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Apr 19, 2021

@pranavkm Since I was out last week I missed whatever design discussions brought us here. It all looks good, but can I check my understanding of the high-level idea is correct?

It looks as if:

  • MetadataUpdateHandlerAttribute is defined in the BCL, so is common to all app frameworks
  • But, each app framework is responsible for separately implementing its own logic to discover all usages of that attribute, and implement its own logic to find both the BeforeUpdate and AfterUpdate methods and invoke them at the right times before and after applying the update

If this is correct, it's totally fine, though there is of course a concern that different app frameworks might not all implement it in the same way. Not a massive issue but was there consideration given to putting this logic inside AssemblyExtensions.ApplyUpdate so that it was independent of each app framework?

To be super clear I'm [update] not suggesting this is a problem - this is just me trying to get in sync with the groupthink on this subject.

@stephentoub
Copy link
Member

To be super clear I'm suggesting this is a problem

Is this missing a "not"? 😄

But, each app framework is responsible for separately implementing its own logic

Each agent is. Some app models will have their own, some will share.

was there consideration given to putting this logic inside AssemblyExtensions.ApplyUpdate so that it was independent of each app framework?

Yes, I'd actually suggested we do this. There was some concern expressed (I believe by @jkotas?) that this would tie the runtime too much to the specific pattern and make it harder to evolve. The attribute in the core library just specifies the type that implements the pattern, but doesn't dictate its shape. @jkotas?

(As an aside, we need to lock down soon on the initial shape of the pattern. I'll open an issue for that.)

@ghost
Copy link

ghost commented Apr 19, 2021

Hi @stephentoub. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@SteveSandersonMS
Copy link
Member

Is this missing a "not"? 😄

Yes, sorry! Updated.

Thanks for the additional info.

@jkotas
Copy link
Member

jkotas commented Apr 19, 2021

There was some concern expressed (I believe by @jkotas?) that this would tie the runtime too much to the specific pattern and make it harder to evolve.

Yes, see dotnet/runtime#49361 (comment) and other comments in that issue.

MetadataUpdateHandlerAttribute is defined in the BCL, so is common to all app frameworks

Nit: Assemblies that target netstandard should be able define a local copy of the attribute if they need to.

@ghost
Copy link

ghost commented Apr 19, 2021

Hi @jkotas. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants