Blazor

How renaming breaks Blazor component parameters

DEV Community: #blazor Zero Heartbeat
Blazor

Blazor Hybrid compiles Razor components into an ordinary managed assembly that ships to the user's machine, so obfuscation makes sense. But parameters reach the component by name through the render tree, and renaming one throws an InvalidOperationException on the first render instead of failing quietly.

Key points

  • The Razor compiler emits parameter names as string literals in `AddComponentParameter` calls; it was `AddAttribute` on .NET 7 and earlier.
  • Component types are wired by metadata token and rename freely; only the string parameter names break.
  • The renderer resolves names through a per-type cache in `ComponentProperties.SetProperties` and throws `InvalidOperationException` when nothing matches.
  • Keep `[Parameter]` and `[CascadingParameter]` names, `RenderFragment` slots such as `ChildContent`, and the `Value`/`ValueChanged` pair behind `@bind-Value`.
  • A namespace keep rule with `members: "public"` preserves exactly that surface while private `@code` members and services still rename.
  • `[JSInvokable]` method names and `DynamicComponent` targets resolved from type-name strings need their own keep entries.

Real-world use

  • A Blazor Hybrid app hosting `BlazorWebView` inside a .NET MAUI, WPF or WinForms shell that ships assemblies to end users.
  • Obfuscating domain logic and licensing checks while keeping the component parameter contract intact.
  • An acceptance test that renders every component at least once against the protected build, not the debug one.

This summary was generated by the agent from the original post on DEV Community: #blazor. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message