# How renaming breaks Blazor component parameters


A Blazor Server app has nothing on the client worth protecting — the assembly runs on your server and the browser only sees HTML. A Blazor **Hybrid** app is the opposite. When you host a `BlazorWebView` inside a .NET MAUI, WPF or WinForms shell, your Razor components compile into an ordinary managed assembly that ships to the user's machine, where a decompiler reads it like any other desktop binary. That is a good reason to obfuscate it. It is also where people get surprised, because a Blazor component does not pass its parameters the way a method passes arguments. It passes them by name, through a render tree, and the names are strings.

## The real question

Rename an assembly and the honest question is always the same: which names does the runtime resolve by their *string*, and which did the compiler already wire as a direct token reference? For most C# the answer is "tokens" — a method call is a `MethodDef` reference, a field access is a `FieldDef`, and renaming rewrites both the definition and every reference together. Component parameters are the exception. The Razor compiler lowers `<Counter IncrementBy="@step" />` into code that names the parameter with a string literal, and the renderer matches that string against the child's properties by reflection. Get that distinction right and a Blazor Hybrid app obfuscates as hard as anything else; get it wrong and the app throws on first render.

## What the Razor compiler emits

Take a trivial component and the parent that uses it.

```razor
@* Counter.razor *@
<p>Count: @Current</p>

@code {
    [Parameter] public int IncrementBy { get; set; } = 1;
    [Parameter] public EventCallback<int> OnChanged { get; set; }
    private int Current;
}
```

```razor
@* Parent.razor *@
<Counter IncrementBy="5" OnChanged="Handle" />

@code {
    private void Handle(int v) { /* ... */ }
}
```

The Razor compiler turns each `.razor` file into a C# class with a `BuildRenderTree` method. The parent's, trimmed to the part that matters, is this:

```csharp
protected override void BuildRenderTree(RenderTreeBuilder __builder)
{
    __builder.OpenComponent<MyApp.Components.Counter>(0);
    __builder.AddComponentParameter(1, "IncrementBy", 5);
    __builder.AddComponentParameter(2, "OnChanged",
        EventCallback.Factory.Create<int>(this, Handle));
    __builder.CloseComponent();
}
```

(On .NET 7 and earlier this was `AddAttribute` rather than `AddComponentParameter`; the string argument is identical.) Two kinds of name now live in this IL, and renaming treats them oppositely.

## Strings versus tokens

`OpenComponent<MyApp.Components.Counter>(0)` carries the `Counter` type as a generic type argument — a metadata token, emitted by `ldtoken`/`typeof` plumbing the JIT resolves to the `TypeDef`. Rename `Counter` to `a` and Nebula rewrites the row and this reference together; the component still opens. The component type name is free.

The parameter names are not. `"IncrementBy"` and `"OnChanged"` are user string constants — plain `ldstr` loads into the `#US` heap:

```
IL_0007:  ldstr      "IncrementBy"
IL_000c:  ldc.i4.5
IL_000d:  box        [System.Private.CoreLib]System.Int32
IL_0012:  callvirt   instance void RenderTreeBuilder::AddComponentParameter(int32, string, object)
```

Nothing in that `ldstr` tells the obfuscator it names a property. Nebula renames *metadata* — type, method, field and property names in the tables — and updates the token references to them. It does not rewrite arbitrary string literals to chase a rename, because it cannot know that the text `"IncrementBy"` is meant to equal a property name rather than, say, a log message. So the string stays `"IncrementBy"` while the property it was meant to hit becomes `a`.

What happens next is the whole point. When the renderer instantiates `Counter`, it hands the component a `ParameterView` built from those named attributes and calls `SetParametersAsync`, whose default implementation calls `ComponentProperties.SetProperties`. That method holds a per-type cache — a `Dictionary<string, IPropertySetter>` built once by reflecting over the component's properties and keyed on each `[Parameter]` property's **name**. After obfuscation that dictionary has a key `"a"`. The incoming attribute is named `"IncrementBy"`. No match, and Blazor does not shrug it off:

```
System.InvalidOperationException: Object of type 'MyApp.Components.Counter'
does not have a property matching the name 'IncrementBy'.
```

Unlike a WPF binding — which logs a path error and leaves the control at its fallback — this throws at the first render of the component. That is a gift: the failure is loud and immediate.

<figure class="my-8"><svg viewBox="0 0 740 300" role="img" aria-label="Two groups of names in a Blazor component assembly. Matched by string so must be kept: the parameter name IncrementBy in the render tree, the EventCallback parameter OnChanged, the special ChildContent name, the bind-generated Value and ValueChanged names, and a named cascading parameter. Wired by token so renames freely: the component type Counter referenced by OpenComponent of T, a cascading parameter matched by its type, the private at-code fields and methods, and routable page components discovered by the Route attribute." style="width:100%;height:auto"><defs><style>.hd{font:700 13px system-ui}.lbl{font:600 11.5px ui-monospace,monospace}.s{font:11px system-ui;fill:#475569}.keep{fill:#fff7ed;stroke:#fdba74}.free{fill:#eef4ff;stroke:#8eb4ff}.pill{fill:#ffffff;stroke:#cbd5e1}</style></defs><rect class="keep" x="14" y="14" width="352" height="272" rx="10"/><text class="hd" x="32" y="40" fill="#c2410c">Matched by STRING — must keep</text><rect class="pill" x="32" y="54" width="316" height="46" rx="7"/><text class="lbl" x="46" y="74" fill="#0f172a">IncrementBy</text><text class="s" x="46" y="91">[Parameter] — render tree names it</text><rect class="pill" x="32" y="106" width="316" height="46" rx="7"/><text class="lbl" x="46" y="126" fill="#0f172a">OnChanged</text><text class="s" x="46" y="143">EventCallback parameter — by name</text><rect class="pill" x="32" y="158" width="316" height="46" rx="7"/><text class="lbl" x="46" y="178" fill="#0f172a">Value / ValueChanged</text><text class="s" x="46" y="195">@bind-Value convention names</text><rect class="pill" x="32" y="210" width="316" height="46" rx="7"/><text class="lbl" x="46" y="230" fill="#0f172a">ChildContent</text><text class="s" x="46" y="247">RenderFragment slot — fixed string</text><text class="s" x="32" y="276" fill="#c2410c">the renderer reflects on these by name</text><rect class="free" x="378" y="14" width="348" height="272" rx="10"/><text class="hd" x="396" y="40" fill="#1547e0">Wired by TOKEN — renames free</text><rect class="pill" x="396" y="54" width="312" height="46" rx="7"/><text class="lbl" x="410" y="74" fill="#0f172a">Counter</text><text class="s" x="410" y="91">type — OpenComponent&lt;Counter&gt; token</text><rect class="pill" x="396" y="106" width="312" height="46" rx="7"/><text class="lbl" x="410" y="126" fill="#0f172a">[CascadingParameter]</text><text class="s" x="410" y="143">unnamed — matched by TYPE</text><rect class="pill" x="396" y="158" width="312" height="46" rx="7"/><text class="lbl" x="410" y="178" fill="#0f172a">Current / Handle</text><text class="s" x="410" y="195">@code internals — called in code</text><rect class="pill" x="396" y="210" width="312" height="46" rx="7"/><text class="lbl" x="410" y="230" fill="#0f172a">[Route] page</text><text class="s" x="410" y="247">discovered by attribute, not name</text></svg></figure>

So the keep-list is specific: every `[Parameter]` and `[CascadingParameter]` **property name**, the generated `EventCallback` parameter names, `ChildContent` and any other `RenderFragment` slot, and the `Value`/`ValueChanged` pair that `@bind-Value` expands to. Everything else the component declares — the private `@code` fields and methods, the component types themselves, an unnamed `[CascadingParameter]` matched by type — is referenced by token and renames with no effect on rendering.

## Scoping Nebula

Blazor's own analyzer requires every `[Parameter]` property to be public, so the names you must keep are exactly the *public* surface of your component types. That is a single scoped keep rule. Put a `Counter.razor` component under a `Components` namespace and:

```json
{
  "schemaVersion": 1,
  "inputs": ["bin/Release/net8.0/MyApp.dll"],
  "outputDirectory": "protected",
  "encryptStrings": true,
  "controlFlowObfuscation": true,
  "renaming": {
    "rules": [
      { "pattern": "MyApp.Components.*", "action": "keep", "members": "public" },
      { "pattern": "MyApp.*",            "action": "rename" }
    ]
  }
}
```

The first rule keeps the public parameter names on every component while `members: "public"` lets the private `Current` field, the `Handle` method and the component's own type name rename. The second renames everything else — your services, your domain logic, your licensing checks. The keep is *name-only*: the kept components still get control-flow obfuscation on their method bodies and their string literals encrypted. You surrender renaming on a handful of parameter names, not protection on the code behind them.

If you would rather pin the names in source so they travel with a refactor, Nebula 2.2.0's annotations package does it per member — `[Keep]` on a parameter property keeps just that name and leaves the rest of the component to rename, and the attribute is stripped from the protected output so it adds no runtime dependency:

```csharp
using Nebula.Annotations;

[Parameter, Keep] public int IncrementBy { get; set; } = 1;
```

## Caveats and when it breaks

The loud failure covers the common case, but three edges are quieter. First, **coverage**: a component rendered only behind a screen your smoke test never opens will not throw until a user gets there, so the honest acceptance test exercises every component at least once against the *protected* build, not the debug one. Second, **JS interop**: a `[JSInvokable]` method is called from JavaScript by its method name, so that name is a string contract — keep it, and keep the type if JS resolves it by name too. Third, **`DynamicComponent`**: `<DynamicComponent Type="@t" />` where `t` was produced from a type-name *string* resolves by name and the target type must be kept; where `t` came from `typeof(...)` it is a token and renames freely.

And the framing underneath all of it: this is about protecting your own application's IP. Keep the names the render tree resolves by string; obfuscate the components and the logic behind them.

## Takeaway

A Blazor component passes parameters through a name-keyed render tree, so every `[Parameter]` name lives in your assembly as a string literal the renderer matches by reflection — and renaming it throws on first render rather than failing quietly. The component types, the private `@code` members and the unnamed cascading parameters are wired by token and rename for free. A `members: "public"` keep on your components' namespace draws exactly that line, which is why obfuscating a Blazor Hybrid app is a scoping problem, not a reason to leave the shipped assembly in cleartext. [Nebula.NET](https://delta1labs.com/products/nebula) keeps the parameter contract and obfuscates everything behind it; open the result in [Glass.NET](https://delta1labs.com/products/glass) to confirm your parameter names survived while the component internals read as `a`, `b`, `c`.

