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

Fields on RenderTreeFrame have become properties #25727

Closed
SteveSandersonMS opened this issue Sep 9, 2020 · 1 comment
Closed

Fields on RenderTreeFrame have become properties #25727

SteveSandersonMS opened this issue Sep 9, 2020 · 1 comment
Milestone

Comments

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Sep 9, 2020

This is the discussion issue for aspnet/Announcements#438

Fields on RenderTreeFrame have become properties

In ASP.NET Core 3.0 and 3.1, the RenderTreeFrame struct exposed various readonly public fields, including FrameType, Sequence, and others. Starting from ASP.NET Core 5.0 RC1, all of those readonly public fields have changed to readonly public properties.

We don't expect this change to affect many developers because:

  • Any application or library that simply uses .razor files (or even manual RenderTreeBuilder calls) to define its components would not be referencing this type directly
  • The RenderTreeFrame type itself is regarded as an implementation detail, not intended for use outside the framework. ASP.NET Core 3.0 and later includes an analyzer that issues compiler warnings if the type is being used directly.
  • Even if you do reference RenderTreeFrame directly, this change is binary-breaking but not source-breaking. That is, your existing source code will still compile and behave properly. You will only encounter an issue if compiling against the 3.x framework and then running those binaries against the 5.0 RC1 and later framework.

Version introduced

ASP.NET Core 5.0 RC1

Old behavior

Public members on RenderTreeFrame were defined as fields, for example renderTreeFrame.Sequence and renderTreeFrame.ElementName.

New behavior

Public members on RenderTreeFrame are defined as properties with the same names as before, for example renderTreeFrame.Sequence and renderTreeFrame.ElementName.

If older precompiled code has not been recompiled since this change, it may throw an exception similar to MissingFieldException: Field not found: 'Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame.FrameType'.

Reason for change

This change was necessary in order to implement some high-impact performance improvements in Blazor component rendering on ASP.NET Core 5.0 while retaining the same level of safety and encapsulation as before.

Recommended action

The vast majority of Blazor developers will not be affected and do not need to take action. This is most likely to affect library/package authors, but still only rarely. Specifically:

  • If you are developing an application, and either staying on ASP.NET Core 3.x or upgrading to 5.0 RC1 or later, you don't need to make any changes to your own code.
    • However if you depend on a library that needs to upgrade to account for this change, then you would need to update to a newer version of that library.
  • If you are developing a library, and intend to support only ASP.NET Core 5.0 RC1 or later, you don't need to take any action. Just ensure that your csproj declares the TargetFramework value net5.0.
  • If you are developing a library, and intend to support both ASP.NET Core 3.x and 5.0, then check whether or not your code attempts to read any of the members of RenderTreeFrame (for example, evaluating someRenderTreeFrame.FrameType).
    • Most libraries will not do that. This includes libraries that contain .razor components. In this case you don't need to take any action.
    • However, if your library does do that, then you will need to use multitargeting to support both netstandard2.1 and net5.0. First, in your csproj, replace the existing <TargetFramework> with <TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>. Then instead of referencing Microsoft.AspNetCore.Components with a fixed version number such as 3.0.0, use a conditional reference to account for both versions you wish to support. For example:
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.0-rc.1.*" Condition="'$(TargetFramework)' != 'netstandard2.0'" />

For further clarification, see this diff showing how @jsakamoto already upgraded his Toolbelt.Blazor.HeadElement library in this way.

Category

ASP.NET

Affected APIs

Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame


Issue metadata

  • Issue type: breaking-change
@ghost
Copy link

ghost commented Nov 12, 2020

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 Nov 12, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant