<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zero Heartbeat</title>
    <description>The latest articles on DEV Community by Zero Heartbeat (@zero_heartbeat_06a3625d7a).</description>
    <link>https://dev.to/zero_heartbeat_06a3625d7a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3782380%2Fa9edbbf7-36b9-434e-8c5d-238ab3ad0caf.png</url>
      <title>DEV Community: Zero Heartbeat</title>
      <link>https://dev.to/zero_heartbeat_06a3625d7a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zero_heartbeat_06a3625d7a"/>
    <language>en</language>
    <item>
      <title>ReadyToRun and obfuscation: get the ordering right or ship a native leak</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Mon, 16 Nov 2026 02:12:10 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/readytorun-and-obfuscation-get-the-ordering-right-or-ship-a-native-leak-2eed</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/readytorun-and-obfuscation-get-the-ordering-right-or-ship-a-native-leak-2eed</guid>
      <description>&lt;p&gt;Most .NET protection advice treats obfuscation and publishing as two independent steps you can do in either order. For an ordinary framework-dependent build that is roughly true. For a &lt;strong&gt;ReadyToRun&lt;/strong&gt; build it is not — and getting the order wrong produces a shipped artifact that leaks the exact logic you obfuscated, while silently throwing away the startup benefit you turned R2R on for in the first place.&lt;/p&gt;

&lt;p&gt;The reason is structural, not a bug: a ReadyToRun assembly is not one representation of your code, it is &lt;em&gt;two&lt;/em&gt;. Obfuscation only ever touches one of them. This post is about which one, why the second copy is compiled from whatever the first looked like at the moment crossgen ran, and how to sequence Nebula.NET so both copies end up protected.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a ReadyToRun build actually produces
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;PublishReadyToRun=true&lt;/code&gt; runs the crossgen2 compiler during &lt;code&gt;dotnet publish&lt;/code&gt;. Crossgen reads the managed assemblies and, for each method, emits &lt;strong&gt;native machine code&lt;/strong&gt; ahead of time, embedding it into the assembly alongside a ReadyToRun header. The goal is faster startup: the runtime can execute the precompiled native code instead of JIT-compiling the method on first call.&lt;/p&gt;

&lt;p&gt;The critical fact — the one the whole ordering question turns on — is that &lt;strong&gt;ReadyToRun is not Native AOT&lt;/strong&gt;. It does not remove your IL. The published assembly is still a completely ordinary .NET assembly: full metadata, full IL, full managed method bodies, &lt;em&gt;plus&lt;/em&gt; a native-code section that duplicates the hot methods. The IL stays because it is the authoritative fallback. If the R2R image is not valid for the current runtime — wrong architecture, a version-bubble mismatch, a modified module — the CLR discards the native code and JITs from the IL instead. R2R is an optimization layered over your assembly, never a replacement for it.&lt;/p&gt;

&lt;p&gt;So after a ReadyToRun publish you are shipping two independent encodings of every precompiled method:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the &lt;strong&gt;IL method body&lt;/strong&gt;, which a decompiler turns back into near-original C#, and&lt;/li&gt;
&lt;li&gt;the &lt;strong&gt;native compilation&lt;/strong&gt; of that same method, which a native disassembler reads directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Obfuscation is an IL-to-IL transform. It rewrites the first encoding. It cannot touch the second — the native code is opaque to it. The only lever you have over the native copy is &lt;em&gt;what the IL looked like when crossgen compiled it&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ordering trap
&lt;/h2&gt;

&lt;p&gt;Picture the tempting pipeline: build, publish with ReadyToRun, then run the obfuscator over the finished publish folder because that is the artifact you ship. It feels right — protect the thing you hand out. It is exactly backwards.&lt;/p&gt;

&lt;p&gt;By the time your obfuscator runs, crossgen has already compiled the native code &lt;strong&gt;from your clean, unobfuscated IL&lt;/strong&gt;. Your license check, your key-derivation routine, your pricing math — all of it is now sitting in the native section as a faithful, fully-optimized machine-code implementation of the original algorithm. Your obfuscator then flattens the &lt;em&gt;IL&lt;/em&gt; copy of that method, encrypts its strings, maybe virtualizes it. The IL copy is beautifully protected. The native copy, compiled minutes earlier, is an untouched second record of the same logic that no IL transform will ever reach. An attacker simply disassembles the native method and reads the control flow you thought you had hidden.&lt;/p&gt;

&lt;p&gt;There is a second, quieter failure stacked on top. Obfuscation rewrites the module: new metadata tokens, new names, new method bodies, a new MVID. The ReadyToRun image was keyed to the &lt;em&gt;pre-obfuscation&lt;/em&gt; module. Mutating the assembly after crossgen invalidates the R2R header's integrity and version checks, so at load time the runtime rejects the native image and falls back to JITting the IL. You paid R2R's size cost, shipped a native copy of your unprotected logic, &lt;strong&gt;and&lt;/strong&gt; lost the startup win. Three bad outcomes from one ordering mistake.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Obfuscate before crossgen
&lt;/h2&gt;

&lt;p&gt;The rule falls straight out of the diagram: the IL that crossgen compiles must already be obfuscated. Concretely, obfuscation has to land &lt;em&gt;after&lt;/em&gt; the C# compiler produces your assemblies and &lt;em&gt;before&lt;/em&gt; &lt;code&gt;dotnet publish&lt;/code&gt; runs the ReadyToRun pass. There are two clean ways to arrange that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CI two-stage.&lt;/strong&gt; Build, obfuscate the compiled output, then publish with ReadyToRun pointed at the already-protected assemblies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet build -c Release -p:PublishReadyToRun=false
nebula --config nebula.config.json            &lt;span class="c"&gt;# rewrites the IL in place&lt;/span&gt;
dotnet publish -c Release --no-build \
  -p:PublishReadyToRun=true -o out            &lt;span class="c"&gt;# crossgen now compiles protected IL&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;nebula.config.json&lt;/code&gt; keeps everything R2R and reflection depend on, and applies the heavy transforms where they matter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"schemaVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"inputs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"bin/Release/net8.0/MyApp.dll"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"bin/Release/net8.0/MyApp.Core.dll"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"outputDirectory"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"bin/Release/net8.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"preservePublicApi"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"encryptStrings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"controlFlowObfuscation"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"autoProtectLicensing"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because crossgen reads the assemblies in &lt;code&gt;bin/Release/net8.0&lt;/code&gt; at publish time, the native code it emits is compiled from the flattened, string-encrypted IL — the two encodings now agree, and both are protected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An MSBuild hook&lt;/strong&gt;, so a plain &lt;code&gt;dotnet publish&lt;/code&gt; is already correct. The one thing that matters is that the obfuscation &lt;code&gt;Exec&lt;/code&gt; runs before the SDK's ReadyToRun compilation, not after it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Target&lt;/span&gt; &lt;span class="na"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"NebulaProtect"&lt;/span&gt; &lt;span class="na"&gt;AfterTargets&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Build"&lt;/span&gt; &lt;span class="na"&gt;BeforeTargets&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Publish"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;Exec&lt;/span&gt; &lt;span class="na"&gt;Command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"nebula --config $(ProjectDir)nebula.config.json"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/Target&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whichever you use, the principle is the same one that governs &lt;a href="https://delta1labs.com/blog/obfuscate-native-aot-single-file-dotnet" rel="noopener noreferrer"&gt;Native AOT and single-file publishing&lt;/a&gt;: protection belongs on the managed IL, between compile and publish. R2R just raises the stakes, because here the publish step does not merely &lt;em&gt;package&lt;/em&gt; your IL — it compiles a second, independent copy of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What each encoding looks like
&lt;/h2&gt;

&lt;p&gt;Take a representative enforcement method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;IsLicensed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StartsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"LIC-"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ValidateSignature&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"https://api.example.com/v1/activate"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obfuscate the IL &lt;strong&gt;before&lt;/strong&gt; crossgen and the IL copy decompiles to a flattened dispatcher with the prefix and endpoint pulled from the encrypted string store at runtime:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;a&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="no"&gt;A_0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="no"&gt;A_0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StartsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Strings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x3f1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;b&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;A_0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Strings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x412&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="cm"&gt;/* ... */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Crucially, the native method crossgen produces is now a compilation of &lt;em&gt;that&lt;/em&gt; dispatcher — same opaque branch structure, no literal URL, nothing to read off cleanly. Note that .NET string literals live in the metadata &lt;code&gt;#US&lt;/code&gt; heap, not inlined into native code, so string encryption protects both encodings through metadata regardless of R2R; it is the &lt;strong&gt;control flow and the shape of the algorithm&lt;/strong&gt; that the native copy would otherwise expose, and here it exposes the obfuscated shape.&lt;/p&gt;

&lt;p&gt;Obfuscate &lt;strong&gt;after&lt;/strong&gt; crossgen and the IL copy looks identical to the protected version above — but the native section is a direct machine-code translation of the clean original: a recognizable prefix comparison, a call into signature validation, the branch structure of your real method, fully optimized and perfectly legible to anyone who disassembles the R2R image. The IL obfuscation was real work spent protecting the copy nobody needs to read.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verifying the R2R build is actually protected
&lt;/h2&gt;

&lt;p&gt;Two quick checks turn the ordering guarantee into evidence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The R2R image is present and valid.&lt;/strong&gt; After the protected publish, confirm the assembly still carries a ReadyToRun header (the SDK's &lt;code&gt;crossgen2&lt;/code&gt;/&lt;code&gt;r2rdump&lt;/code&gt; tooling will dump it). If obfuscation had run after crossgen, the image would be absent or rejected at load and you would silently be back on the JIT — so a valid header is proof the ordering held.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The native method bodies map to renamed members.&lt;/strong&gt; Dump the R2R method list; the entrypoints should correspond to Nebula's renamed identifiers (&lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, …), because they were compiled from the obfuscated metadata. Original names surfacing in the native method table mean crossgen ran first — a red flag.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the IL side, verify as you would any protected build: open the shipped assembly in &lt;a href="https://delta1labs.com/products/glass" rel="noopener noreferrer"&gt;Glass.NET&lt;/a&gt; or your decompiler of choice and confirm the sensitive methods come back as flattened dispatchers rather than clean C#, exactly as covered in &lt;a href="https://delta1labs.com/blog/verify-obfuscation-ci" rel="noopener noreferrer"&gt;verifying obfuscation in CI&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;ReadyToRun is a good startup optimization and worth shipping. But it fundamentally changes the obfuscation question, because it compiles a second, native copy of your code from whatever IL it is handed. Obfuscate first and that copy inherits your protection; obfuscate last and it becomes a clean, decompiler-independent record of the logic you were trying to hide — while the mismatched R2R image gets discarded at load, costing you the one benefit you turned it on for. There is no middle ground and no "we'll protect the published folder later." Crossgen must compile protected IL. Sequence Nebula before the ReadyToRun pass, verify the native methods carry the renamed shape, and both halves of the image tell the same, protected story.&lt;/p&gt;

</description>
      <category>readytorun</category>
      <category>nebula</category>
    </item>
    <item>
      <title>Instrumenting Keyright license verification with OpenTelemetry: the metrics, traces, and tags that matter</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Mon, 16 Nov 2026 02:08:55 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/instrumenting-keyright-license-verification-with-opentelemetry-the-metrics-traces-and-tags-that-3lgk</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/instrumenting-keyright-license-verification-with-opentelemetry-the-metrics-traces-and-tags-that-3lgk</guid>
      <description>&lt;p&gt;You have an &lt;code&gt;ActivitySource&lt;/code&gt; around your outbound HTTP calls, a histogram on your database round-trips, and a dashboard that lights up the moment your payment provider gets slow. Then look at the one call that decides whether your software is allowed to run tonight — the license verification — and it is almost always a blind spot. It fails, it slows down, it quietly starts serving every customer from a cached lease because your &lt;a href="https://delta1labs.com/products/keyright" rel="noopener noreferrer"&gt;Keyright&lt;/a&gt; instance is briefly unreachable, and the first anyone hears of it is a support ticket.&lt;/p&gt;

&lt;p&gt;A license check is a dependency call. It deserves the same treatment as any other: a metric you can alert on and a span you can read when one activation is mysteriously slow. This post wires a Keyright verification into OpenTelemetry end to end — and, just as importantly, keeps the one secret involved out of your telemetry backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two signals, two jobs
&lt;/h2&gt;

&lt;p&gt;Metrics and traces answer different questions, and you want both.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Metrics&lt;/strong&gt; answer &lt;em&gt;"is the fleet healthy right now?"&lt;/em&gt; They are cheap, pre-aggregated counters and histograms: how many verifications succeeded, how many were denied, how long they took, how close the active license is to expiry. This is what a dashboard and an alert rule read.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Traces&lt;/strong&gt; answer &lt;em&gt;"why was this one slow or wrong?"&lt;/em&gt; A span around a single verification carries its timing, its outcome, and whether the answer came from the service or from a cached lease — the detail you need the one time a customer in a particular region reports a stall.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The temptation is to lean on logs for all of it. Logs are the wrong tool for the first question: you cannot cheaply ask "what fraction of verifications in the last five minutes were denied?" of a log aggregator, but a counter answers it for free.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Meter and its instruments
&lt;/h2&gt;

&lt;p&gt;Everything starts with one &lt;code&gt;Meter&lt;/code&gt; and the instruments hung off it. Declare them once, statically, so there is a single place that owns the names and units.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Diagnostics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Diagnostics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Metrics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Keyright&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// LicenseInfo, LicenseStatus, RefreshStatus&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;LicenseTelemetry&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;MeterName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Delta1.Licensing"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;ActivitySourceName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Delta1.Licensing"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;Meter&lt;/span&gt; &lt;span class="nc"&gt;Meter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MeterName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;internal&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;ActivitySource&lt;/span&gt; &lt;span class="nc"&gt;Activity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ActivitySourceName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// How many verifications, tagged by status/outcome/source.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;VerifyCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="nc"&gt;Meter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateCounter&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;long&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"keyright.verify.count"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;unit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"{verification}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"License verifications, tagged by status and source."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// How long each verification took.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;Histogram&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;VerifyDuration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="nc"&gt;Meter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateHistogram&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"keyright.verify.duration"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;unit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ms"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Wall time spent verifying a license."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// How close the active license is to expiry (an async gauge, polled by the SDK).&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;volatile&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;_daysRemaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;LicenseTelemetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;Meter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateObservableGauge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"keyright.license.days_remaining"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_daysRemaining&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;unit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Days until the active license expires; -1 when unknown."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;SetDaysRemaining&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_daysRemaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three instruments, three questions. The &lt;code&gt;Counter&amp;lt;long&amp;gt;&lt;/code&gt; is the rate of verifications and, once tagged, the rate of &lt;em&gt;denials&lt;/em&gt;. The &lt;code&gt;Histogram&amp;lt;double&amp;gt;&lt;/code&gt; is latency — and because a verification may hit the network, its tail is the thing you watch. The &lt;code&gt;ObservableGauge&lt;/code&gt; is a pull-based reading: OpenTelemetry calls the callback at collection time, so you never emit a point unless a scrape asks for one, which is exactly right for a slow-moving value like "days until expiry."&lt;/p&gt;

&lt;h2&gt;
  
  
  Recording a verification
&lt;/h2&gt;

&lt;p&gt;Keyright's &lt;code&gt;Validate()&lt;/code&gt; returns a &lt;code&gt;LicenseInfo&lt;/code&gt; whose &lt;code&gt;Status&lt;/code&gt; is a bounded enum (&lt;code&gt;Valid&lt;/code&gt;, &lt;code&gt;Expired&lt;/code&gt;, &lt;code&gt;Revoked&lt;/code&gt;, &lt;code&gt;SignatureInvalid&lt;/code&gt;, &lt;code&gt;MachineMismatch&lt;/code&gt;, &lt;code&gt;ClockTampered&lt;/code&gt;, &lt;code&gt;NoLicense&lt;/code&gt;) and whose &lt;code&gt;DaysRemaining&lt;/code&gt; / &lt;code&gt;IsExpiringSoon&lt;/code&gt; you already lean on elsewhere. The refresh path, through &lt;code&gt;RefreshAsync&lt;/code&gt;, tells you &lt;em&gt;where&lt;/em&gt; the answer came from — the service, a 304-not-modified cache hit, or a cached lease served because the service was unreachable. That provenance is the single most useful tag you can attach.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;RecordVerify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LicenseInfo&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;elapsedMs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Keep this list SHORT and BOUNDED — see the cardinality rule below.&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;tags&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TagList&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                              &lt;span class="c1"&gt;// 7 values&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"outcome"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;LicenseStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Valid&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"allow"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"deny"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// 2 values&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                                              &lt;span class="c1"&gt;// online | cache | grace&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"expiring_soon"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsExpiringSoon&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;                            &lt;span class="c1"&gt;// true | false&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;VerifyCount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;VerifyDuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Record&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;elapsedMs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;SetDaysRemaining&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DaysRemaining&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The tags you keep, and the ones that will cost you
&lt;/h2&gt;

&lt;p&gt;A metric's cost is not the number of points — it is the number of distinct &lt;strong&gt;tag combinations&lt;/strong&gt;, because each one is a separate time series your backend stores and indexes. Four bounded tags like the ones above multiply out to a few dozen series: fine. Add one unbounded tag and the series count explodes with your customer base. This is called a cardinality blowout, and a license check is a minefield for it, because the most &lt;em&gt;obviously relevant&lt;/em&gt; fields are exactly the ones you must not use as labels.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;license key&lt;/strong&gt; is a bearer secret. It must never be a tag value — that ships the key straight into your metrics store and your traces backend, the same mistake the logging guidance warns about, just in a different pipe.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;licensee name&lt;/strong&gt;, the &lt;strong&gt;machine fingerprint&lt;/strong&gt;, and any &lt;strong&gt;key fingerprint&lt;/strong&gt; are unbounded. One series per customer or per device defeats the point of a pre-aggregated metric and quietly runs up your observability bill.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rule is simple: tags are for things with a small, fixed set of values. Identity goes on a &lt;strong&gt;span&lt;/strong&gt;, where it is a one-off attribute on a single trace you sampled, not a label multiplied across every point forever.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tracing the refresh path
&lt;/h2&gt;

&lt;p&gt;Metrics tell you &lt;em&gt;that&lt;/em&gt; denials rose; a span tells you &lt;em&gt;why&lt;/em&gt; one verification behaved the way it did. Wrap the verification in an activity, time it off a monotonic &lt;code&gt;Stopwatch&lt;/code&gt; (the wall clock can jump mid-measurement), and record the provenance as span attributes and events.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;LicenseInfo&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;VerifyAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;licenseKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CancellationToken&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Activity&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LicenseTelemetry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Activity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StartActivity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"license.verify"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ActivityKind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StartNew&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"online"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Pull the freshest lease we can; fall through to cache/grace on an outage.&lt;/span&gt;
    &lt;span class="nc"&gt;RefreshResult&lt;/span&gt; &lt;span class="n"&gt;refresh&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RefreshAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;refresh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Status&lt;/span&gt; &lt;span class="k"&gt;switch&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;RefreshStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Refreshed&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"online"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;RefreshStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NotModified&lt;/span&gt;        &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"cache"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// 304 — nothing changed&lt;/span&gt;
        &lt;span class="nc"&gt;RefreshStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ServiceUnreachable&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"grace"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// served from a signed cached lease&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt;                                &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"online"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;LicenseInfo&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;licenseKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Identity and detail live on the span — one trace, not a metric label.&lt;/span&gt;
    &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"license.status"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"license.source"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"license.days_remaining"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DaysRemaining&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"license.key_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;KeyId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// non-secret handle, if your payload carries one&lt;/span&gt;
    &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;LicenseStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Valid&lt;/span&gt;
        &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;ActivityStatusCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Ok&lt;/span&gt;
        &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ActivityStatusCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"grace"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ActivityEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"served-from-grace-window"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;LicenseTelemetry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RecordVerify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Elapsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TotalMilliseconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note the division of labour. &lt;code&gt;license.key_id&lt;/code&gt; — a non-secret handle, never the raw key — goes on the span, where it is a single attribute on a sampled trace, not a label stamped on a time series forever. The &lt;code&gt;source == "grace"&lt;/code&gt; event is the breadcrumb that, months later, explains why a verification stayed green for an hour while the service was down.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wiring the exporter
&lt;/h2&gt;

&lt;p&gt;Register the meter and the source with the OpenTelemetry SDK and point them at your collector. The license instruments ride the same OTLP pipeline as the rest of your app; there is nothing license-specific about the transport.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddOpenTelemetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ConfigureResource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"acme-designer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithMetrics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddMeter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LicenseTelemetry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;MeterName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"keyright.verify.duration"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ExplicitBucketHistogramConfiguration&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Buckets sized for a call that is usually local but sometimes hits the network.&lt;/span&gt;
            &lt;span class="nc"&gt;Boundaries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddOtlpExporter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithTracing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LicenseTelemetry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ActivitySourceName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddOtlpExporter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The explicit histogram boundaries matter: the default buckets are tuned for sub-millisecond work, and they will bunch every network-bound verification into one overflow bucket where you can no longer see the tail. Size the buckets for the call you are actually making.&lt;/p&gt;

&lt;h2&gt;
  
  
  The four things worth alerting on
&lt;/h2&gt;

&lt;p&gt;With the counter, histogram and gauge flowing, four rules cover the failure modes that actually page someone. Expressed loosely, backend-agnostic:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Deny rate.&lt;/strong&gt; &lt;code&gt;rate(keyright.verify.count{outcome="deny"})&lt;/code&gt; climbing is either a revocation that propagated, a bad clock on a fleet of machines, or a signing-key mismatch after a rotation. A sudden step is the signal.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grace saturation.&lt;/strong&gt; A nonzero and rising share of &lt;code&gt;source="grace"&lt;/code&gt; means your instance has been unreachable long enough that clients are living off cached leases. It is not customer-visible &lt;em&gt;yet&lt;/em&gt; — which is exactly why you want the alert before &lt;code&gt;MaxOfflineDuration&lt;/code&gt; runs out and it becomes an outage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verify latency tail.&lt;/strong&gt; The p99 of &lt;code&gt;keyright.verify.duration&lt;/code&gt; is your early warning that the refresh round-trip is degrading, well before it turns into timeouts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Days remaining.&lt;/strong&gt; &lt;code&gt;keyright.license.days_remaining&lt;/code&gt; dropping below a threshold (say 7) is the fleet-wide version of the renewal nudge — one alert instead of one surprised customer per expiry.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The payoff
&lt;/h2&gt;

&lt;p&gt;None of this changes what the license check &lt;em&gt;decides&lt;/em&gt; — the gate still fails closed on a revoked or expired key. What changes is that the decision is no longer invisible. A verification is now a first-class dependency on your dashboard: you can see its rate, its latency, and the moment it quietly shifts from answering online to answering from grace. And because the design draws a hard line between bounded tags and identity, you get all of that observability without a single license key, licensee name, or machine id ever landing in your telemetry backend.&lt;/p&gt;

</description>
      <category>observability</category>
      <category>keyright</category>
    </item>
    <item>
      <title>Decoding custom attribute blobs: from #Blob bytes back to [Cache(30, ...)]</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Mon, 16 Nov 2026 02:07:21 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/decoding-custom-attribute-blobs-from-blob-bytes-back-to-cache30--1o23</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/decoding-custom-attribute-blobs-from-blob-bytes-back-to-cache30--1o23</guid>
      <description>&lt;p&gt;Most C# constructs lower into IL instructions. Attributes do not: an attribute application compiles into &lt;em&gt;data&lt;/em&gt;, a packed binary record stored in the &lt;code&gt;#Blob&lt;/code&gt; heap and pointed at by a row in the &lt;code&gt;CustomAttribute&lt;/code&gt; metadata table. There is no code to read back, only bytes to decode — and the decode is driven by a signature that lives somewhere else entirely. Getting a named argument's field-versus-property tag wrong, or misreading an enum's embedded type name, produces an attribute that looks plausible and binds to the wrong member. This post walks the exact byte layout and shows what &lt;a href="https://delta1labs.com/products/glass" rel="noopener noreferrer"&gt;Glass.NET&lt;/a&gt; reconstructs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The source
&lt;/h2&gt;

&lt;p&gt;A single attribute, carrying two positional arguments and two named ones — one property, one field — is enough to exercise every part of the format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;AttributeUsage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AttributeTargets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Class&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CacheAttribute&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Attribute&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;CacheAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Seconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Region&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Seconds&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Region&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;SlidingExpiration&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;  &lt;span class="c1"&gt;// property&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Priority&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                           &lt;span class="c1"&gt;// field&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"catalog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SlidingExpiration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Priority&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application on &lt;code&gt;ProductService&lt;/code&gt; says: call the &lt;code&gt;(int, string)&lt;/code&gt; constructor with &lt;code&gt;30&lt;/code&gt; and &lt;code&gt;"catalog"&lt;/code&gt;, then set the &lt;code&gt;SlidingExpiration&lt;/code&gt; property to &lt;code&gt;true&lt;/code&gt; and the &lt;code&gt;Priority&lt;/code&gt; field to &lt;code&gt;5&lt;/code&gt;. None of those member names or values is stored as text in source form — they are serialized into a blob whose shape is fixed by ECMA-335 §II.23.3.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the metadata really holds
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ildasm&lt;/code&gt; and the Glass IL view both render the application as a constructor reference followed by the raw blob:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.custom instance void CacheAttribute::.ctor(int32, string) = (
    01 00 1E 00 00 00 07 63 61 74 61 6C 6F 67 02 00
    54 02 11 53 6C 69 64 69 6E 67 45 78 70 69 72 61
    74 69 6F 6E 01 53 08 08 50 72 69 6F 72 69 74 79
    05 00 00 00 )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fifty-two bytes. Every field of the attribute is in there, in a strict order, with no delimiters and no names for the positional arguments. Here is the same blob, sliced:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;01 00&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Prolog — always &lt;code&gt;0x0001&lt;/code&gt;, little-endian&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;1E 00 00 00&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fixed arg 1: &lt;code&gt;int32&lt;/code&gt; = 30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;07&lt;/code&gt; + &lt;code&gt;63 61 74 61 6C 6F 67&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Fixed arg 2: &lt;code&gt;SerString&lt;/code&gt;, length 7, UTF-8 "catalog"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;02 00&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;NumNamed = 2 named arguments follow&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;54&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Named arg 1 tag: &lt;code&gt;PROPERTY&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;02&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Element type &lt;code&gt;BOOLEAN&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;11&lt;/code&gt; + &lt;code&gt;53 6C 69 64 …&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Name &lt;code&gt;SerString&lt;/code&gt;, length 17, "SlidingExpiration"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;01&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Value: &lt;code&gt;true&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;53&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Named arg 2 tag: &lt;code&gt;FIELD&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;08&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Element type &lt;code&gt;I4&lt;/code&gt; (int32)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;08&lt;/code&gt; + &lt;code&gt;50 72 69 6F …&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Name &lt;code&gt;SerString&lt;/code&gt;, length 8, "Priority"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;05 00 00 00&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Value: 5&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  The prolog and the fixed arguments
&lt;/h3&gt;

&lt;p&gt;The first two bytes are a version prolog, always &lt;code&gt;0x0001&lt;/code&gt;. After it come the &lt;em&gt;fixed&lt;/em&gt; arguments — the constructor's positional parameters — serialized back to back in declaration order, with &lt;strong&gt;no type tags and no names&lt;/strong&gt;. The blob stores &lt;code&gt;1E 00 00 00&lt;/code&gt; and &lt;code&gt;07 catalog&lt;/code&gt;; it does not record that the first is &lt;code&gt;seconds&lt;/code&gt; or the second &lt;code&gt;region&lt;/code&gt;. The only way to know that the four bytes &lt;code&gt;1E 00 00 00&lt;/code&gt; are an &lt;code&gt;int32&lt;/code&gt; and the next group is a string is to read the &lt;em&gt;constructor signature&lt;/em&gt; from the &lt;code&gt;MethodDef&lt;/code&gt;/&lt;code&gt;MemberRef&lt;/code&gt; the &lt;code&gt;CustomAttribute&lt;/code&gt; row points at. Fixed arguments are decoded by external signature; the blob alone is ambiguous.&lt;/p&gt;

&lt;p&gt;Strings use the &lt;code&gt;SerString&lt;/code&gt; encoding: a compressed unsigned length (here a single byte &lt;code&gt;0x07&lt;/code&gt;) followed by that many UTF-8 bytes. A compressed length is one, two, or four bytes depending on magnitude — the same scheme used throughout the metadata heaps — and a null string is the single byte &lt;code&gt;0xFF&lt;/code&gt;, distinct from an empty string's &lt;code&gt;0x00&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The named arguments are self-describing
&lt;/h3&gt;

&lt;p&gt;After the fixed arguments comes a 2-byte count — &lt;code&gt;02 00&lt;/code&gt; here — and then each named argument, which unlike the fixed ones &lt;strong&gt;carries its own type information&lt;/strong&gt;. Each begins with a tag byte that is the piece of information C# syntax throws away:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;0x53&lt;/code&gt; = &lt;code&gt;FIELD&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;0x54&lt;/code&gt; = &lt;code&gt;PROPERTY&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In source, &lt;code&gt;SlidingExpiration = true&lt;/code&gt; and &lt;code&gt;Priority = 5&lt;/code&gt; look identical — both are &lt;code&gt;Name = value&lt;/code&gt;. In the blob they are distinguished at byte offset zero of each named argument. The tag is followed by an element-type byte (&lt;code&gt;0x02&lt;/code&gt; for &lt;code&gt;BOOLEAN&lt;/code&gt;, &lt;code&gt;0x08&lt;/code&gt; for &lt;code&gt;I4&lt;/code&gt;, &lt;code&gt;0x0E&lt;/code&gt; for &lt;code&gt;STRING&lt;/code&gt;, …), a &lt;code&gt;SerString&lt;/code&gt; for the member name, and the value serialized according to that element type.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;/p&gt;
Byte layout of a custom attribute blob: prolog, fixed arguments decoded by constructor signature, a named-argument count, and self-describing named arguments
&lt;br&gt;
&lt;br&gt;
Prolog&lt;br&gt;
01 00&lt;br&gt;
&lt;br&gt;
Fixed args — no tags, no names&lt;br&gt;
1E 00 00 00 · 07 "catalog"&lt;br&gt;
&lt;br&gt;
NumNamed&lt;br&gt;
02 00&lt;br&gt;
decoded against the (int32, string) constructor signature&lt;br&gt;
&lt;br&gt;
Named arg 1 — self-describing&lt;br&gt;
54  PROPERTY tag&lt;br&gt;
02  BOOLEAN element type&lt;br&gt;
11 "SlidingExpiration"&lt;br&gt;
01  value = true&lt;br&gt;
&lt;br&gt;
Named arg 2 — self-describing&lt;br&gt;
53  FIELD tag&lt;br&gt;
08  I4 element type&lt;br&gt;
08 "Priority"&lt;br&gt;
05 00 00 00  value = 5&lt;br&gt;
&lt;br&gt;
&lt;br&gt;


&lt;p&gt;The asymmetry is the whole story: fixed arguments lean on an external signature, named arguments describe themselves. A decoder has to switch strategies halfway through the blob.&lt;/p&gt;
&lt;h2&gt;
  
  
  The awkward cases: enums, Type, and arrays
&lt;/h2&gt;

&lt;p&gt;Three argument kinds complicate the "element type byte then value" rule, and they are where naive decoders drift.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enums.&lt;/strong&gt; An enum argument does not have a primitive element-type byte. It is encoded as &lt;code&gt;0x55&lt;/code&gt; followed by a &lt;code&gt;SerString&lt;/code&gt; naming the enum type, then the value serialized as the enum's &lt;em&gt;underlying&lt;/em&gt; integer type. Suppose &lt;code&gt;CacheAttribute&lt;/code&gt; also accepted a &lt;code&gt;CachePriority&lt;/code&gt; enum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"catalog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Level&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CachePriority&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;High&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The named argument's bytes would be &lt;code&gt;54&lt;/code&gt; (property) &lt;code&gt;55&lt;/code&gt; (enum) then &lt;code&gt;"...CachePriority"&lt;/code&gt; as a &lt;code&gt;SerString&lt;/code&gt;, then &lt;code&gt;02 00 00 00&lt;/code&gt; for the underlying &lt;code&gt;int&lt;/code&gt; value &lt;code&gt;2&lt;/code&gt;. The blob stores the &lt;em&gt;number&lt;/em&gt;, not the member name &lt;code&gt;High&lt;/code&gt;. To render &lt;code&gt;CachePriority.High&lt;/code&gt;, Glass resolves the enum type by its embedded name and maps &lt;code&gt;2&lt;/code&gt; back to the member — or emits &lt;code&gt;(CachePriority)2&lt;/code&gt; when no single member matches a flag combination.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;System.Type.&lt;/strong&gt; A &lt;code&gt;typeof(...)&lt;/code&gt; argument is serialized as element type &lt;code&gt;0x50&lt;/code&gt; followed by a &lt;code&gt;SerString&lt;/code&gt; of the type's name (assembly-qualified when it lives elsewhere). Glass parses that name back into a &lt;code&gt;typeof(T)&lt;/code&gt; expression rather than leaving a string literal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arrays.&lt;/strong&gt; An array argument is &lt;code&gt;SZARRAY&lt;/code&gt; (&lt;code&gt;0x1D&lt;/code&gt;), the element type, a 4-byte element count, then the elements packed in sequence (&lt;code&gt;0xFFFFFFFF&lt;/code&gt; marks a null array, distinct from a zero-length one). Each element is serialized by the element type — so a &lt;code&gt;string[]&lt;/code&gt; is a count followed by that many &lt;code&gt;SerString&lt;/code&gt;s.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Glass reconstructs
&lt;/h2&gt;

&lt;p&gt;Glass reads the &lt;code&gt;CustomAttribute&lt;/code&gt; row, resolves the constructor to recover the fixed-argument types, decodes the blob in two passes (signature-driven for fixed args, self-describing for named args), honours each &lt;code&gt;FIELD&lt;/code&gt;/&lt;code&gt;PROPERTY&lt;/code&gt; tag to bind the right member, and resolves enum and &lt;code&gt;Type&lt;/code&gt; names. From the 52 bytes above it produces exactly the original application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"catalog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SlidingExpiration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Priority&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A decoder that skipped the named-argument tag byte, or that treated the enum's embedded type string as a positional value, would emit something that &lt;em&gt;compiles&lt;/em&gt; but names the wrong member or the wrong constant — the same class of silent, on-the-page-invisible error as dropping an overflow suffix.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reading it yourself
&lt;/h3&gt;

&lt;p&gt;Open any assembly in Glass, select a decorated type or method, and switch to the &lt;strong&gt;IL&lt;/strong&gt; view to see the raw &lt;code&gt;.custom&lt;/code&gt; blob next to the reconstructed C#. Line up the prolog &lt;code&gt;01 00&lt;/code&gt;, count the fixed arguments against the constructor signature, find the &lt;code&gt;02 00&lt;/code&gt; named-argument count, and watch the &lt;code&gt;53&lt;/code&gt;/&lt;code&gt;54&lt;/code&gt; tags pick field versus property. For a quick experiment, add an enum-typed property to an attribute and recompile — you will see the &lt;code&gt;0x55&lt;/code&gt; element type and the embedded type name appear in the blob, with the numeric value stored where the member name never is.&lt;/p&gt;

&lt;p&gt;Glass.NET is a free .NET decompiler for inspecting assemblies you have the right to inspect — your own builds, your dependencies, and third-party binaries you are licensed to analyse. Decoding a custom attribute blob faithfully, down to the field-versus-property tag, is the difference between reading metadata and guessing at it.&lt;/p&gt;

</description>
      <category>decompilation</category>
      <category>glass</category>
    </item>
    <item>
      <title>Can obfuscation hide a connection string? What Nebula protects, and what it cannot</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Sun, 15 Nov 2026 23:13:11 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/can-obfuscation-hide-a-connection-string-what-nebula-protects-and-what-it-cannot-5bbb</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/can-obfuscation-hide-a-connection-string-what-nebula-protects-and-what-it-cannot-5bbb</guid>
      <description>&lt;p&gt;Every protection tool gets the same question, usually phrased as a demand: &lt;em&gt;"I have a connection string in my desktop app — can you make it so nobody can read it?"&lt;/em&gt; The honest answer is a comparison, not a yes. A secret that ships inside client-side code is recoverable in principle, because the process has to use it, which means the process has to hold the plaintext at some instant. What obfuscation changes is the &lt;strong&gt;cost&lt;/strong&gt; of recovery — from "double-click a resource viewer" to "attach a debugger, find the decode, reproduce it" — and whether the string is sitting in cleartext for a &lt;code&gt;strings.exe&lt;/code&gt; dump or a web crawler to find.&lt;/p&gt;

&lt;p&gt;This post is the comparison in full. Where a connection string actually hides in a shipped assembly, what Nebula.NET string and resource encryption do to each hiding place, where the ceiling is and why, and the layering that keeps the secret out of the binary entirely when it can.&lt;/p&gt;

&lt;h2&gt;
  
  
  The three places a secret hides
&lt;/h2&gt;

&lt;p&gt;A connection string, an API key, a symmetric key for an embedded data file — all of them reach the shipped assembly through one of three routes, and each decompiles differently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;As a literal in code.&lt;/strong&gt; The most common and the most exposed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Server=db.internal;Database=App;User Id=svc;Password=S3cr3t!;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The C# compiler emits that as a single &lt;code&gt;ldstr&lt;/code&gt; into the string heap. It is not encrypted, not encoded, not hidden — it is UTF-16 text in a well-known table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;ldstr&lt;/span&gt;      &lt;span class="s2"&gt;"Server=db.internal;Database=App;User Id=svc;Password=S3cr3t!;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;As an embedded &lt;code&gt;appsettings.json&lt;/code&gt; resource.&lt;/strong&gt; You set the file to &lt;code&gt;EmbeddedResource&lt;/code&gt; so it travels inside the DLL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ItemGroup&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;EmbeddedResource&lt;/span&gt; &lt;span class="na"&gt;Include&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"appsettings.Production.json"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ItemGroup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the JSON — connection strings and all — is a length-prefixed blob in the &lt;code&gt;ManifestResource&lt;/code&gt; table. No decompiler needed; &lt;code&gt;System.Resources&lt;/code&gt; reads it, and so does every resource viewer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;As a value bound through configuration.&lt;/strong&gt; The string lives in &lt;code&gt;appsettings.json&lt;/code&gt; on disk and is read by &lt;code&gt;IConfiguration&lt;/code&gt; into an options POCO. This is the only one of the three that is &lt;em&gt;not&lt;/em&gt; in the assembly — but it is a plaintext file sitting next to the binary, which is a different exposure, not a smaller one.&lt;/p&gt;

&lt;p&gt;Note the split: the first two ship the secret &lt;em&gt;inside&lt;/em&gt; the binary, where obfuscation can act on it; the third ships it &lt;em&gt;beside&lt;/em&gt; the binary, where obfuscation cannot reach it at all. That distinction drives the whole comparison.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What a decompiler sees before protection
&lt;/h2&gt;

&lt;p&gt;Open an unprotected build in &lt;a href="https://delta1labs.com/products/glass" rel="noopener noreferrer"&gt;Glass.NET&lt;/a&gt; (or any decompiler) and the literal case needs no effort at all. The IL view shows the &lt;code&gt;ldstr&lt;/code&gt;; the string heap view lists the value. You do not even have to find the method — a decompiler's metadata browser lists every string in the assembly, and &lt;code&gt;Server=…;Password=…;&lt;/code&gt; sorts right next to your error messages.&lt;/p&gt;

&lt;p&gt;The embedded-resource case is worse, because it does not require a decompiler at all. Expand the assembly's &lt;strong&gt;resources&lt;/strong&gt; node and the &lt;code&gt;appsettings.Production.json&lt;/code&gt; resource is right there; one click dumps the JSON. The BCL even ships the reader, so a five-line program recovers it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;asm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Assembly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LoadFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;asm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetManifestResourceStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MyApp.appsettings.Production.json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StreamReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadToEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// connection strings and all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"I compiled it into the DLL" is not protection. It is a slightly less obvious filename.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Nebula changes, concretely
&lt;/h2&gt;

&lt;p&gt;Nebula.NET acts on the two in-assembly cases. &lt;strong&gt;String encryption&lt;/strong&gt; rewrites the literal. The &lt;code&gt;ldstr&lt;/code&gt; is replaced by a call to a generated decode routine that takes an opaque token and returns the plaintext at the point of use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight llvm"&gt;&lt;code&gt;&lt;span class="n"&gt;ldc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i4&lt;/span&gt;     &lt;span class="mh"&gt;0x3f91a7&lt;/span&gt;
&lt;span class="k"&gt;call&lt;/span&gt;       &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Nebula&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;int32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cleartext connection string is gone from the string heap. A metadata browser now lists an encoded blob; a &lt;code&gt;strings&lt;/code&gt; dump finds nothing; a decompiler shows a call into protected code rather than a value. You scope it in &lt;code&gt;nebula.config.json&lt;/code&gt; so the valuable literals are covered without taxing a measured hot path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"schemaVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"inputs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"bin/Release/net8.0/MyApp.dll"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"outputDirectory"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"protected"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="nl"&gt;"stringEncryption"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"include"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"MyApp.Data.*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"MyApp.Security.*"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="nl"&gt;"resourceEncryption"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"include"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"MyApp.appsettings.Production.json"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"exclude"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"*.g.resources"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="nl"&gt;"controlFlow"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Resource encryption&lt;/strong&gt; handles the embedded JSON. The pass replaces the plaintext resource bytes with ciphertext at build time and installs a resolver so that &lt;code&gt;GetManifestResourceStream&lt;/code&gt; — and therefore the configuration provider that reads it — receives a decrypting stream for the protected names. Your call site is unchanged:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ConfigurationBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddJsonStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Assembly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetExecutingAssembly&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetManifestResourceStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MyApp.appsettings.Production.json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This still binds, because the resolver decrypts transparently. What changed is only what a static viewer sees on disk: ciphertext, not a connection string. Run it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nebula protect --config nebula.config.json --out bin/Protected
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both passes do the same thing in different parts of the PE: they remove the &lt;em&gt;trivial disclosure&lt;/em&gt; — the value you could read in one step — and force any recovery through the obfuscated code, where it costs real effort. That is the entire, honest claim.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ceiling, and why it exists
&lt;/h2&gt;

&lt;p&gt;Here is the part a vendor should state plainly: &lt;strong&gt;encryption does not make a client-side secret unrecoverable.&lt;/strong&gt; The decryption key ships in the assembly too, because the process must decrypt the value to use it. Nebula derives that key through the same protected code path that guards your methods — it is not a constant sitting in a field — so recovering it means reverse-engineering control-flow-flattened, string-encrypted code rather than reading a literal. That is a large increase in cost. It is not infinity.&lt;/p&gt;

&lt;p&gt;The sharper limit is runtime. The instant your code does this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SqlConnection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;decryptedConnString&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the plaintext connection string exists as a live &lt;code&gt;string&lt;/code&gt; on the managed heap. An attacker who can run your process — which, on a client machine, they can — can attach a debugger, break on &lt;code&gt;SqlConnection..ctor&lt;/code&gt;, and read the argument. No decompilation required. The same is true of the decrypted &lt;code&gt;appsettings.json&lt;/code&gt;: once the configuration provider has read it, the values are objects in memory. Obfuscation raises the bar against &lt;em&gt;static&lt;/em&gt; inspection and against casual dumps. It cannot win against a debugger attached to a process that is about to use the secret, because at that moment the secret is, by necessity, plaintext.&lt;/p&gt;

&lt;p&gt;This is not a weakness specific to Nebula; it is the nature of client-side secrets. Any tool that claims otherwise is selling the claim, not the protection.&lt;/p&gt;

&lt;h2&gt;
  
  
  The layering that actually works
&lt;/h2&gt;

&lt;p&gt;Because of that ceiling, the real strategy is a hierarchy, and obfuscation is the last tier, not the first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tier 1 — do not ship the secret.&lt;/strong&gt; A connection string to a server &lt;em&gt;you&lt;/em&gt; control, a third-party API key, anything that authenticates the client to a backend: this should not be in the binary at all. Keep it out of source with user-secrets in development, supply it from an environment variable or your platform's managed identity in production, or — best — never hand the client a long-lived credential and instead broker access so the server issues a short-lived, scoped token. A secret that is never in the artifact has no recovery cost because there is nothing to recover. Obfuscation is irrelevant to Tier 1, and that is the point: the strongest protection is absence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tier 2 — for the secret you genuinely must embed, raise the cost.&lt;/strong&gt; Some secrets have to ship: the public key your app uses to verify a license, a symmetric key that decrypts an embedded proprietary data file, a pinned certificate. These cannot be moved to a server because the app must function offline or must not trust the network for this check. For these, Nebula is exactly the right tool. Encrypt the literal, encrypt the resource, flatten the control flow around the derivation, and — for the highest-value routine — virtualize the method so the key derivation runs on an interpreted instruction set rather than readable IL. You are not making recovery impossible; you are making it expensive enough that it is not worth it relative to what the secret protects.&lt;/p&gt;

&lt;p&gt;The decision is a short table.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;The secret&lt;/th&gt;
&lt;th&gt;Can it leave the binary?&lt;/th&gt;
&lt;th&gt;Treatment&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;DB connection string, backend API key&lt;/td&gt;
&lt;td&gt;Yes — authenticates to &lt;em&gt;your&lt;/em&gt; server&lt;/td&gt;
&lt;td&gt;Tier 1: broker it, issue short-lived tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Third-party key tied to your account&lt;/td&gt;
&lt;td&gt;Usually&lt;/td&gt;
&lt;td&gt;Tier 1: proxy the call through your backend&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;License-verification public key&lt;/td&gt;
&lt;td&gt;No — must verify offline&lt;/td&gt;
&lt;td&gt;Tier 2: ship it, string-encrypt + control-flow&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Symmetric key for an embedded data file&lt;/td&gt;
&lt;td&gt;No — app must decrypt locally&lt;/td&gt;
&lt;td&gt;Tier 2: resource-encrypt + virtualize the derivation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The mistake is to skip Tier 1 and ask obfuscation to do its job. Obfuscation makes a &lt;em&gt;must-ship&lt;/em&gt; secret costly to extract. It does nothing to justify shipping a secret that never needed to be there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verify what you shipped
&lt;/h2&gt;

&lt;p&gt;After a protected build, confirm the two in-assembly cases are actually closed. Open &lt;code&gt;protected/MyApp.dll&lt;/code&gt; in Glass.NET: the string heap should no longer list your connection string, and the &lt;code&gt;appsettings.Production.json&lt;/code&gt; resource should dump as ciphertext, not JSON. Make it a CI gate — a script that opens the protected output, asserts no resource decodes to recognizable JSON and no literal matches a &lt;code&gt;Password=&lt;/code&gt; pattern, and fails the build if either does. That catches the day someone adds a new secret-bearing literal to a namespace your &lt;code&gt;include&lt;/code&gt; list does not cover.&lt;/p&gt;

&lt;p&gt;A protected binary that still grep-matches your password means the pass did not reach it; a clean one means you have done everything client-side obfuscation can do — and told the truth about where that ends.&lt;/p&gt;

&lt;p&gt;See &lt;a href="https://delta1labs.com/products/nebula" rel="noopener noreferrer"&gt;Nebula.NET&lt;/a&gt; for the full transform pipeline and the &lt;code&gt;nebula.config.json&lt;/code&gt; reference, &lt;a href="https://delta1labs.com/blog/encrypt-embedded-resources-dotnet/" rel="noopener noreferrer"&gt;encrypting embedded resources&lt;/a&gt; for the resource pass in depth, and &lt;a href="https://delta1labs.com/products/glass" rel="noopener noreferrer"&gt;Glass.NET&lt;/a&gt; for verifying what a decompiler can still read.&lt;/p&gt;

</description>
      <category>obfuscation</category>
      <category>nebula</category>
    </item>
    <item>
      <title>Scoping a Keyright license to an environment: migrating from one key everywhere to a signed staging/production boundary</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Sun, 15 Nov 2026 23:09:03 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/scoping-a-keyright-license-to-an-environment-migrating-from-one-key-everywhere-to-a-signed-1a3p</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/scoping-a-keyright-license-to-an-environment-migrating-from-one-key-everywhere-to-a-signed-1a3p</guid>
      <description>&lt;p&gt;Watch a single license file long enough and it ends up everywhere. You issue one key for the product, drop it into the production deployment, and within a sprint it has been copied into the staging environment so the pre-prod smoke tests pass, pasted into a developer's &lt;code&gt;appsettings.Development.json&lt;/code&gt;, and baked into a CI secret so integration tests can run. Now four environments present the &lt;em&gt;same&lt;/em&gt; signed key to your &lt;a href="https://delta1labs.com/products/keyright/" rel="noopener noreferrer"&gt;Keyright&lt;/a&gt; instance, and three facts you would like to have are gone: you cannot tell from a validation which environment it came from, a staging key that leaks is a production key, and the day you want to expire the staging key early you discover it is the production key.&lt;/p&gt;

&lt;p&gt;This post is a migration guide. We will compare the three ways teams actually separate environments, pick the one that keeps a single product and a single code path, and move to it on Keyright without a flag day — including the part most rollouts skip, which is letting the old unscoped key keep working while the new scoped keys roll out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three ways to tell production from staging
&lt;/h2&gt;

&lt;p&gt;There are only three shapes for this, and they differ in how much ceremony and how much duplication they cost.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A product per environment.&lt;/strong&gt; Register &lt;code&gt;acme-studio-prod&lt;/code&gt; and &lt;code&gt;acme-studio-staging&lt;/code&gt; as separate products in your issuing service, each with its own signing key, and ship a different public key per build. It works, and the separation is absolute, but you now maintain two of everything — two key pairs, two entitlement catalogues, two rotation schedules — and a feature you add to one you must remember to add to the other. This is the right answer only when staging and production are genuinely different products with different capabilities, which they rarely are.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A bare file per environment, same product.&lt;/strong&gt; Issue two licenses for the one product and rely on &lt;em&gt;deployment discipline&lt;/em&gt; to keep them apart. Nothing in the key says which environment it is for, so nothing stops the staging file from running in production; the moment someone copies the wrong file you are back where you started, and the signed payload is no help because it carries no environment at all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One product, an environment written into the signed payload.&lt;/strong&gt; Keep a single product and a single public key, and add a &lt;code&gt;scope:env&lt;/code&gt; entitlement that names the environment(s) the key is licensed for. The key for staging literally cannot validate as licensed in production, because the app checks its own environment against the claim and the claim is covered by the signature. No second product, no second rotation, one gate. This is the shape we migrate to.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What the key says
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;scope:env&lt;/code&gt; entitlement is an ordinary signed entitlement — a string in the canonical payload the signature covers — holding a comma-separated set of environment names the key is valid in. A production key names one environment; a key you want to reuse across your own pre-prod tiers names several.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"product"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="s2"&gt;"acme-studio"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"licensee"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Contoso Ltd"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"expiryUtc"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2027-11-16T00:00:00Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"tier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="s2"&gt;"pro"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"entitlements"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"scope:env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="s2"&gt;"production"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"export"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="s2"&gt;"true"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"max-seats"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="s2"&gt;"400"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"signature"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"…"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;scope:&lt;/code&gt; prefix is a convention, not a Keyright feature, and it earns its keep the same way &lt;code&gt;site:&lt;/code&gt; does: it keeps &lt;em&gt;where this key may run&lt;/em&gt; visibly separate from &lt;em&gt;what this key unlocks&lt;/em&gt;, so nobody later gates the &lt;code&gt;export&lt;/code&gt; feature on an environment or vice versa. Because the value is inside the signed payload, a customer — or a developer in a hurry — can no more change &lt;code&gt;production&lt;/code&gt; to &lt;code&gt;staging&lt;/code&gt; than they can push the expiry out a year: one changed byte and the app sees &lt;code&gt;LicenseStatus.SignatureInvalid&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the app knows about its own environment
&lt;/h2&gt;

&lt;p&gt;The app has to answer "which environment am I?" from its own configuration, offline, at startup. In an ASP.NET Core or generic-host app the answer already exists: &lt;code&gt;IHostEnvironment.EnvironmentName&lt;/code&gt;, which the host resolves from &lt;code&gt;DOTNET_ENVIRONMENT&lt;/code&gt; (or &lt;code&gt;ASPNETCORE_ENVIRONMENT&lt;/code&gt; for the web host), defaulting to &lt;code&gt;Production&lt;/code&gt; when neither is set. Wrap it behind an interface so the gate stays testable and so non-host apps can supply the same answer from a raw environment variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;IAppEnvironment&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;   &lt;span class="c1"&gt;// "Production", "Staging", … ; null when genuinely unknown&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Host apps: let the framework resolve DOTNET_ENVIRONMENT / ASPNETCORE_ENVIRONMENT.&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HostAppEnvironment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IHostEnvironment&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IAppEnvironment&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EnvironmentName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EnvironmentName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Console / worker without a host: same variables, explicit fallback order.&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;VariableAppEnvironment&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IAppEnvironment&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetEnvironmentVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"DOTNET_ENVIRONMENT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetEnvironmentVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ASPNETCORE_ENVIRONMENT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="c1"&gt;// intentionally NOT defaulting to "Production": see the gate — unknown fails closed&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One deliberate choice: the host wrapper inherits the framework's "default to Production" behaviour, but the variable wrapper does &lt;em&gt;not&lt;/em&gt;. For a gate you want an unset environment to be &lt;em&gt;unknown&lt;/em&gt;, not silently &lt;em&gt;production&lt;/em&gt; — an unknown environment on a scoped key should be refused, not waved through as the most privileged tier. The host case is the exception because the framework has already made the decision for the whole app, consistently, before your gate runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The gate
&lt;/h2&gt;

&lt;p&gt;The gate runs after &lt;code&gt;Validate()&lt;/code&gt; and only does anything when the key actually carries a &lt;code&gt;scope:env&lt;/code&gt; claim. Matching is a case-insensitive membership test against the comma-separated set, so &lt;code&gt;scope:env = "staging,production"&lt;/code&gt; admits both.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="nc"&gt;EnvStatus&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NotEnvScoped&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Unknown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;WrongEnv&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EnvGate&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;EnvStatus&lt;/span&gt; &lt;span class="nc"&gt;Check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LicenseInfo&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;IAppEnvironment&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;claim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Entitlements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetRaw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"scope:env"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;claim&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;EnvStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NotEnvScoped&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// legacy/unscoped key: nothing to check&lt;/span&gt;

        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;here&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;here&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;EnvStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Unknown&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;             &lt;span class="c1"&gt;// fail closed: unknown ≠ allowed&lt;/span&gt;

        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;claim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;','&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;StringSplitOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TrimEntries&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;StringSplitOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RemoveEmptyEntries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;here&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;StringComparison&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OrdinalIgnoreCase&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;EnvStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;EnvStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WrongEnv&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                &lt;span class="c1"&gt;// e.g. staging key launched in Production&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wire it at startup, after the signature and expiry checks the SDK already performs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;KeyrightClient&lt;/span&gt; &lt;span class="nc"&gt;License&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;KeyrightClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KeyrightOptions&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Product&lt;/span&gt;         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"acme-studio"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;PublicKeyBase64&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AcmeKeys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LicensePublicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// public key only; safe to ship&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;LicenseInfo&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;License&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;             &lt;span class="c1"&gt;// signature, product, expiry&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsValid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;RunEvaluation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;EnvGate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                &lt;span class="c1"&gt;// app resolved from DI or the variable wrapper&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;EnvStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Ok&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nc"&gt;EnvStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NotEnvScoped&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;RunEvaluation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;              &lt;span class="c1"&gt;// "this key is licensed for staging, not Production"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;RunLicensed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ordering matters: the env check runs &lt;em&gt;after&lt;/em&gt; &lt;code&gt;IsValid&lt;/code&gt;. A key with a bad signature never reaches the gate, so the &lt;code&gt;scope:env&lt;/code&gt; string an attacker could have typed in is never read — entitlements are only trustworthy once the signature over them has verified, and Keyright returns an empty entitlement set for anything that did not validate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Migrating without a flag day
&lt;/h2&gt;

&lt;p&gt;The trap in every enforcement rollout is the flag day: you ship the gate and the scoped keys in the same release, a customer's production node comes up holding the &lt;em&gt;old&lt;/em&gt; unscoped key, the gate finds no claim it recognises, and you have turned an upgrade into an outage. The gate above is written to avoid exactly that — &lt;code&gt;NotEnvScoped&lt;/code&gt; is a &lt;em&gt;pass&lt;/em&gt; — but it is worth being explicit about the three phases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 1 — backward-compatible issuance.&lt;/strong&gt; Start issuing new keys with &lt;code&gt;scope:env&lt;/code&gt; present, and leave every existing unscoped key alone. Because a missing claim returns &lt;code&gt;NotEnvScoped&lt;/code&gt; and that is treated as "runs anywhere", the legacy production key keeps working untouched while the new staging and production keys carry their scope. No node has to be re-keyed to upgrade.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 2 — audit, don't enforce.&lt;/strong&gt; Ship the gate computing &lt;code&gt;EnvStatus&lt;/code&gt; but &lt;em&gt;logging&lt;/em&gt; it instead of acting on it. Read the logs for a release. This is where you discover the environment names you did not predict — the &lt;code&gt;Staging2&lt;/code&gt; someone stood up, the blue/green slot that reports &lt;code&gt;Production&lt;/code&gt; under a different &lt;code&gt;DOTNET_ENVIRONMENT&lt;/code&gt;, the load test rig that inherited a production key. The &lt;a href="https://delta1labs.com/blog/license-enforcement-audit-mode-shadow-rollout/" rel="noopener noreferrer"&gt;audit-mode rollout&lt;/a&gt; pattern applies here unchanged.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 3 — enforce, and re-issue.&lt;/strong&gt; Flip the gate to acting on &lt;code&gt;WrongEnv&lt;/code&gt;/&lt;code&gt;Unknown&lt;/code&gt;, and re-issue the remaining legacy unscoped keys as scoped ones on their next renewal. The unscoped key is not &lt;em&gt;insecure&lt;/em&gt; — it simply says nothing about environment — so there is no urgency, only a direction: every renewal narrows the blast radius of a leak by one more environment.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Issuing a scoped key, and the diagnostic
&lt;/h2&gt;

&lt;p&gt;On the issuing side the scope is just another entitlement to set. However you mint keys — admin API or CLI against your Keyright instance — the production and staging keys differ in one field:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# production key&lt;/span&gt;
keyright issue --product acme-studio --licensee &lt;span class="s2"&gt;"Contoso Ltd"&lt;/span&gt; \
  --entitlement scope:env=production --entitlement max-seats=400 --expiry 2027-11-16

&lt;span class="c"&gt;# a single key reusable across your own pre-prod tiers&lt;/span&gt;
keyright issue --product acme-studio --licensee &lt;span class="s2"&gt;"Contoso Ltd (pre-prod)"&lt;/span&gt; \
  --entitlement scope:env=staging,qa --expiry 2027-11-16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Close the hand-off gap the same way the site-license flow does: ship a one-line diagnostic that prints the environment the gate would check, from exactly the code path the gate uses, so "it says wrong environment" never becomes a support ticket about what the environment &lt;em&gt;actually&lt;/em&gt; is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// yourapp --env-info&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;VariableAppEnvironment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Resolved environment : {app.Name ?? "&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unknown&lt;/span&gt; — &lt;span class="no"&gt;DOTNET_ENVIRONMENT&lt;/span&gt; &lt;span class="n"&gt;unset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What environment scoping proves — and what it does not
&lt;/h2&gt;

&lt;p&gt;Be honest in your own threat model about what this binding is.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The environment is self-reported.&lt;/strong&gt; &lt;code&gt;scope:env&lt;/code&gt; is checked against a value the running process reads from its own configuration, and an operator who controls that configuration can set &lt;code&gt;DOTNET_ENVIRONMENT=Production&lt;/code&gt; on a staging box and the gate will pass. So this is not a wall against a determined operator who owns the host — it is not meant to be. What it &lt;em&gt;does&lt;/em&gt; stop is the accident that is a hundred times more common: the staging key copied into production and quietly running there for a year, the developer key that leaked and now unlocks the production tier, the CI secret that turns out to be a production license. Those are configuration mistakes, and &lt;code&gt;scope:env&lt;/code&gt; turns them from silent into a loud, specific refusal with the reason attached.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It is a hygiene and telemetry boundary, not a seat count.&lt;/strong&gt; Scoping does not limit &lt;em&gt;how many&lt;/em&gt; machines run a key — a production key with &lt;code&gt;max-seats&lt;/code&gt; still counts seats the way it always did; the scope only limits &lt;em&gt;which tier&lt;/em&gt; it will run in. The two are orthogonal, and it is worth keeping them so: a key that is both seat-limited and environment-scoped tells you, in its telemetry, both how many production nodes are live and that none of them are secretly staging.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For an untrusted boundary, scope differently.&lt;/strong&gt; If "staging" is a &lt;em&gt;different customer's&lt;/em&gt; environment rather than your own tier, self-reported configuration is the wrong instrument entirely — bind to something the other party cannot assert, as the &lt;a href="https://delta1labs.com/blog/keyright-site-license-domain-binding/" rel="noopener noreferrer"&gt;site-license domain binding&lt;/a&gt; does, or issue genuinely separate products. Environment scoping earns its place when the environments are all &lt;em&gt;yours&lt;/em&gt;, the risk is a mistake rather than an adversary, and you want the key itself — not a deployment runbook — to be the thing that keeps production and staging apart.&lt;/p&gt;

&lt;p&gt;A license that runs everywhere is convenient right up to the first leak, when "everywhere" stops being a feature. Writing the environment into the signed key costs one entitlement and one twenty-line gate, it migrates in without a flag day because an unscoped key still runs anywhere, and it gives every validation an answer to the question your audit log has been missing: &lt;em&gt;which environment was this?&lt;/em&gt;&lt;/p&gt;

</description>
      <category>licensing</category>
      <category>keyright</category>
    </item>
    <item>
      <title>Decompiling checked arithmetic: add.ovf, conv.ovf, and rebuilding the checked block</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Sun, 15 Nov 2026 23:07:19 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/decompiling-checked-arithmetic-addovf-convovf-and-rebuilding-the-checked-block-1m61</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/decompiling-checked-arithmetic-addovf-convovf-and-rebuilding-the-checked-block-1m61</guid>
      <description>&lt;p&gt;A &lt;code&gt;checked&lt;/code&gt; or &lt;code&gt;unchecked&lt;/code&gt; keyword is one of the few C# constructs that leaves no direct fingerprint in metadata. There is no attribute, no flag, no scope record that says "overflow checking was on here." The information survives in a completely different form: it is smeared across the individual arithmetic instructions, each of which comes in a checking and a non-checking variant. Reconstructing the keyword means reading those instructions back and working out the smallest block of source that would have produced exactly that pattern — and getting it wrong changes what the program does. This post walks the lowering in both directions and shows what &lt;a href="https://delta1labs.com/products/glass" rel="noopener noreferrer"&gt;Glass.NET&lt;/a&gt; rebuilds.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the source looks like
&lt;/h2&gt;

&lt;p&gt;Overflow checking controls one thing: what happens when an integer operation produces a result too large for its type. Under &lt;code&gt;unchecked&lt;/code&gt; (the C# default) the result wraps around silently. Under &lt;code&gt;checked&lt;/code&gt; the runtime throws &lt;code&gt;OverflowException&lt;/code&gt;. The keyword can scope a block or a single expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Money&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;checked&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt; &lt;span class="nc"&gt;ToByte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;checked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Fast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;unchecked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three methods, three decisions. &lt;code&gt;Total&lt;/code&gt; adds with overflow checking on. &lt;code&gt;ToByte&lt;/code&gt; narrows an &lt;code&gt;int&lt;/code&gt; to a &lt;code&gt;byte&lt;/code&gt; with a range check. &lt;code&gt;Fast&lt;/code&gt; multiplies with checking explicitly off. Nothing about these intentions is stored as such — each becomes a choice of opcode.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the compiler really emits
&lt;/h2&gt;

&lt;p&gt;Here are the three method bodies as Glass shows them in the IL view. Watch the suffixes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.method public hidebysig static int32 Total (int32 a, int32 b) cil managed
{
    IL_0000: ldarg.0
    IL_0001: ldarg.1
    IL_0002: add.ovf
    IL_0003: ret
}

.method public hidebysig static uint8 ToByte (int32 n) cil managed
{
    IL_0000: ldarg.0
    IL_0001: conv.ovf.u1
    IL_0002: ret
}

.method public hidebysig static int32 Fast (int32 a, int32 b) cil managed
{
    IL_0000: ldarg.0
    IL_0001: ldarg.1
    IL_0002: mul
    IL_0003: ret
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The entire difference between &lt;code&gt;checked&lt;/code&gt; and &lt;code&gt;unchecked&lt;/code&gt; is three characters of opcode mnemonic. &lt;code&gt;add.ovf&lt;/code&gt; is &lt;code&gt;add&lt;/code&gt; with a trap on overflow. &lt;code&gt;conv.ovf.u1&lt;/code&gt; is the range-checking narrowing conversion to unsigned 8-bit; its unchecked twin is the bare &lt;code&gt;conv.u1&lt;/code&gt;, which truncates. &lt;code&gt;mul&lt;/code&gt; is the plain multiply with no trap. The compiler made one checking decision per instruction and threw the block structure away.&lt;/p&gt;

&lt;h3&gt;
  
  
  The conversion opcodes are a family
&lt;/h3&gt;

&lt;p&gt;Narrowing conversions are where overflow checking matters most, because every assignment to a smaller integer type is a potential loss. The CLR gives each target type a matched pair:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;conv.u1       // int -&amp;gt; byte, truncating      (unchecked)
conv.ovf.u1   // int -&amp;gt; byte, range-checked    (checked)
conv.i2       // int -&amp;gt; short, truncating      (unchecked)
conv.ovf.i2   // int -&amp;gt; short, range-checked    (checked)
conv.ovf.i4.un // uint -&amp;gt; int, range-checked, source treated as unsigned
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;.un&lt;/code&gt; suffix on the last one is the second axis: it tells the conversion to treat its &lt;em&gt;source&lt;/em&gt; as unsigned when deciding whether the value fits. That is how &lt;code&gt;checked((int)someUInt)&lt;/code&gt; is distinguished from &lt;code&gt;checked((int)someInt)&lt;/code&gt; — same target, different interpretation of the bits already on the stack. A decompiler has to carry both the &lt;code&gt;.ovf&lt;/code&gt; and the &lt;code&gt;.un&lt;/code&gt; flags through, because dropping either one silently changes the conversion's semantics.&lt;/p&gt;

&lt;h2&gt;
  
  
  The asymmetry: where checked does nothing
&lt;/h2&gt;

&lt;p&gt;Not every arithmetic operation has an overflow variant, and this is the part naive reconstruction gets wrong. There is no &lt;code&gt;div.ovf&lt;/code&gt; and no &lt;code&gt;rem.ovf&lt;/code&gt;. Integer division has exactly one overflow case — &lt;code&gt;int.MinValue / -1&lt;/code&gt;, whose true result is &lt;code&gt;2147483648&lt;/code&gt; and does not fit in an &lt;code&gt;int&lt;/code&gt; — and ECMA-335 makes that case throw unconditionally, in checked and unchecked contexts alike. Since the behaviour is identical either way, the compiler emits plain &lt;code&gt;div&lt;/code&gt; whether or not you wrote &lt;code&gt;checked&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The practical consequence for decompilation: a &lt;code&gt;div&lt;/code&gt; instruction carries &lt;em&gt;no&lt;/em&gt; overflow-context information. If a method contains &lt;code&gt;checked { return a / b; }&lt;/code&gt;, the IL is indistinguishable from &lt;code&gt;unchecked { return a / b; }&lt;/code&gt;, and Glass will not fabricate a &lt;code&gt;checked&lt;/code&gt; region around a bare &lt;code&gt;div&lt;/code&gt;. It reconstructs context only from instructions that actually encode it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline, end to end
&lt;/h2&gt;

&lt;p&gt;&lt;br&gt;
&lt;/p&gt;
How a checked block compiles to per-instruction overflow opcodes and how Glass.NET rebuilds the smallest checked region
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
1 · Source block&lt;br&gt;
checked {&lt;br&gt;
  return a + b;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
2 · Per-instruction&lt;br&gt;
ldarg.0 / ldarg.1&lt;br&gt;
add.ovf&lt;br&gt;
block boundary erased&lt;br&gt;
&lt;br&gt;
3 · Opcode set&lt;br&gt;
.ovf present → trap&lt;br&gt;
plain → wrap&lt;br&gt;
div → no signal&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Glass.NET reconstructs&lt;br&gt;
checked { return a + b; }&lt;br&gt;
smallest region covering every .ovf instruction, no larger&lt;br&gt;
&lt;br&gt;


&lt;p&gt;The compiler expands one keyword into a set of opcode choices; the decompiler reads the set and infers the narrowest keyword that reproduces it.&lt;/p&gt;
&lt;h2&gt;
  
  
  What a naive decompiler shows — and what Glass shows
&lt;/h2&gt;

&lt;p&gt;A decompiler that ignores overflow suffixes produces source that compiles and reads cleanly but &lt;em&gt;behaves differently&lt;/em&gt;. Drop the &lt;code&gt;.ovf&lt;/code&gt; from &lt;code&gt;conv.ovf.u1&lt;/code&gt; and you have turned a conversion that throws on out-of-range input into one that silently truncates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// suffix ignored — compiles, reads fine, WRONG behaviour&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt; &lt;span class="nc"&gt;ToByte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// truncates 300 to 44&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the dangerous failure mode: the bug is invisible on the page. Glass carries the checking flag through and renders the keyword that restores the exact semantics. It also scopes the block minimally — it does not wrap the whole method in &lt;code&gt;checked&lt;/code&gt; when only one instruction carries &lt;code&gt;.ovf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Money&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;checked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt; &lt;span class="nc"&gt;ToByte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;checked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Fast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note &lt;code&gt;Fast&lt;/code&gt; loses its explicit &lt;code&gt;unchecked&lt;/code&gt;: because unchecked is the language default, &lt;code&gt;a * b&lt;/code&gt; and &lt;code&gt;unchecked(a * b)&lt;/code&gt; compile to the identical &lt;code&gt;mul&lt;/code&gt;, so Glass renders the shorter form that produces the same IL. It adds the keyword only where the opcode choice would otherwise be lost.&lt;/p&gt;

&lt;h3&gt;
  
  
  The one thing IL cannot tell you
&lt;/h3&gt;

&lt;p&gt;If the project was built with &lt;code&gt;&amp;lt;CheckForOverflowUnderflow&amp;gt;true&amp;lt;/CheckForOverflowUnderflow&amp;gt;&lt;/code&gt;, the default context flips for the whole assembly. A bare &lt;code&gt;a + b&lt;/code&gt; then compiles to &lt;code&gt;add.ovf&lt;/code&gt; with no keyword in sight — byte-for-byte identical to an explicit &lt;code&gt;checked(a + b)&lt;/code&gt; in a normal project. Glass reconstructs under the standard default-unchecked assumption, so it will show &lt;code&gt;checked&lt;/code&gt; where the opcodes demand it. It cannot recover a build-wide flag that left no trace, and it does not guess at one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reading it yourself
&lt;/h3&gt;

&lt;p&gt;Open the assembly in Glass, select a method, and switch between the &lt;strong&gt;C#&lt;/strong&gt; and &lt;strong&gt;IL&lt;/strong&gt; views. Line up each &lt;code&gt;checked(...)&lt;/code&gt; region in the source against the &lt;code&gt;.ovf&lt;/code&gt; suffixes in the IL, and find the &lt;code&gt;div&lt;/code&gt; that carries no suffix at all. Then try a narrowing cast both ways in a scratch assembly and watch &lt;code&gt;conv.u1&lt;/code&gt; become &lt;code&gt;conv.ovf.u1&lt;/code&gt; the moment you add the keyword — it is the clearest way to see that overflow checking is an instruction-level decision, not a block the metadata remembers.&lt;/p&gt;

&lt;p&gt;Glass.NET is a free .NET decompiler for inspecting code you have the right to inspect — your own assemblies, your dependencies, and third-party binaries you are licensed to analyse. Preserving semantics-carrying details like the &lt;code&gt;.ovf&lt;/code&gt; suffix is the difference between a decompilation you can trust and one that reads right but runs wrong.&lt;/p&gt;

</description>
      <category>decompilation</category>
      <category>glass</category>
    </item>
    <item>
      <title>Metadata heap compaction and token renumbering: shrinking a .NET assembly after obfuscation</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Sun, 15 Nov 2026 20:08:15 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/metadata-heap-compaction-and-token-renumbering-shrinking-a-net-assembly-after-obfuscation-23il</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/metadata-heap-compaction-and-token-renumbering-shrinking-a-net-assembly-after-obfuscation-23il</guid>
      <description>&lt;p&gt;Rename a few thousand members and you have shortened every identifier in your assembly — &lt;code&gt;CalculateInvoiceTotal&lt;/code&gt; became &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;_pendingReconciliationQueue&lt;/code&gt; became &lt;code&gt;b&lt;/code&gt;. You would expect the file to shrink. Open the two builds in a hex viewer and it often has not: the original long names are still sitting there in the &lt;code&gt;#Strings&lt;/code&gt; heap, orphaned but never removed. Obfuscation changed which strings the metadata tables &lt;em&gt;point at&lt;/em&gt;; it did not reclaim the strings they used to point at.&lt;/p&gt;

&lt;p&gt;This post is about the pass that finishes the job — &lt;strong&gt;metadata heap compaction and token renumbering&lt;/strong&gt;. It is the least glamorous transform Nebula runs and, on a large assembly, one of the most measurable: it is the difference between a rename that only hides names and one that also deletes them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the names actually live
&lt;/h2&gt;

&lt;p&gt;A .NET assembly's metadata is a set of tables (&lt;code&gt;TypeDef&lt;/code&gt;, &lt;code&gt;MethodDef&lt;/code&gt;, &lt;code&gt;Field&lt;/code&gt;, …) plus four heaps the tables index into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;#Strings&lt;/code&gt;&lt;/strong&gt; — null-terminated UTF-8 identifier names: type names, method names, field names, namespaces.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;#US&lt;/code&gt;&lt;/strong&gt; — the user-string heap, holding the UTF-16 string &lt;em&gt;literals&lt;/em&gt; your code loads with &lt;code&gt;ldstr&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;#Blob&lt;/code&gt;&lt;/strong&gt; — signatures, custom-attribute arguments, constant values, marshalling descriptors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;#GUID&lt;/code&gt;&lt;/strong&gt; — module version IDs and friends.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A row in &lt;code&gt;MethodDef&lt;/code&gt; does not store its name; it stores a &lt;strong&gt;&lt;code&gt;#Strings&lt;/code&gt; offset&lt;/strong&gt;. The name &lt;code&gt;"CalculateInvoiceTotal"&lt;/code&gt; lives once in the heap and every token that needs it carries the integer offset where it begins.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Renaming rewrites the &lt;code&gt;Name&lt;/code&gt; field to a new offset. The naive way to get that offset is to &lt;strong&gt;append&lt;/strong&gt; &lt;code&gt;"a\0"&lt;/code&gt; to the end of &lt;code&gt;#Strings&lt;/code&gt; and point there. Fast, correct — and it never touches the old bytes. After a full rename pass the heap holds every original identifier &lt;em&gt;plus&lt;/em&gt; every short replacement. The file can even grow.&lt;/p&gt;

&lt;h2&gt;
  
  
  What compaction does
&lt;/h2&gt;

&lt;p&gt;Compaction treats the heaps as a garbage-collected arena. The steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Mark.&lt;/strong&gt; Walk every table column that is a heap reference — &lt;code&gt;TypeDef.Name&lt;/code&gt;, &lt;code&gt;TypeDef.Namespace&lt;/code&gt;, &lt;code&gt;MethodDef.Name&lt;/code&gt;, &lt;code&gt;Field.Signature&lt;/code&gt;, every &lt;code&gt;ldstr&lt;/code&gt; into &lt;code&gt;#US&lt;/code&gt;, every custom-attribute &lt;code&gt;#Blob&lt;/code&gt; — and record which offsets are actually reachable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sweep and rebuild.&lt;/strong&gt; Allocate fresh heaps containing only the reachable entries, de-duplicated so two identical signatures share one blob.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Renumber.&lt;/strong&gt; Every heap offset in every table is rewritten to its new position. Tokens into the tables themselves are re-packed too, because empty &lt;code&gt;TypeRef&lt;/code&gt;/&lt;code&gt;MemberRef&lt;/code&gt; rows left by merged or removed references can be dropped.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 3 is why this cannot be a peephole fix. A metadata token like &lt;code&gt;0x06000012&lt;/code&gt; (a &lt;code&gt;MethodDef&lt;/code&gt;, row 0x12) is referenced from IL (&lt;code&gt;call 0x06000012&lt;/code&gt;), from other tables, and from the &lt;code&gt;#Blob&lt;/code&gt; signatures. Renumber one table and you must fix every &lt;code&gt;call&lt;/code&gt;, &lt;code&gt;ldtoken&lt;/code&gt;, &lt;code&gt;newobj&lt;/code&gt; and &lt;code&gt;ldstr&lt;/code&gt; that crosses it. Nebula does this as a single coherent remap: it builds an old-token → new-token map, rewrites the tables, then rewrites every method body's IL operands against the same map.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// IL before — operand is a raw metadata token
IL_000a:  ldstr      0x70000A1C      // "CalculateInvoiceTotal failed for order "
IL_000f:  call       0x0A000037      // MemberRef into a #Blob signature

// IL after compaction — same instructions, renumbered operands
IL_000a:  ldstr      0x70000044
IL_000f:  call       0x0A00000B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The instructions are byte-for-byte identical in shape; only the operands move. Get the remap wrong by one row and the assembly throws &lt;code&gt;BadImageFormatException&lt;/code&gt; at load, which is exactly why you do not hand-roll this and why Nebula verifies the rebuilt image before writing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  It is also a hardening pass, not only a size pass
&lt;/h2&gt;

&lt;p&gt;Compaction is usually sold as size, but the security angle is the orphaned &lt;code&gt;#Strings&lt;/code&gt; bytes themselves. A rename that only repoints offsets leaves &lt;code&gt;CalculateInvoiceTotal&lt;/code&gt;, &lt;code&gt;_pendingReconciliationQueue&lt;/code&gt; and every other original name physically present in the file. They no longer resolve through metadata — a decompiler shows &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;c&lt;/code&gt; — but a trivial &lt;code&gt;strings&lt;/code&gt;-style scan over the raw bytes recovers your entire original vocabulary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ strings Acme.Billing.dll &lt;span class="o"&gt;|&lt;/span&gt; grep -i invoice
CalculateInvoiceTotal
InvoiceReconciliationService
_pendingInvoiceBatch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is a real leak. Your method &lt;em&gt;names&lt;/em&gt; often describe your domain as clearly as the code does. Compaction deletes the orphans, so the scan comes back empty and the only names in the file are the meaningless short ones the rename produced. The same applies to &lt;code&gt;#US&lt;/code&gt;: literals you encrypted and replaced still linger in the user-string heap until the heap is rebuilt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turning it on
&lt;/h2&gt;

&lt;p&gt;Compaction runs after rename, string encryption and resource processing, because it must see the final set of live references. In &lt;code&gt;nebula.config.json&lt;/code&gt; it is a stage under the output, on by default when you rename but configurable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"schemaVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"inputs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"bin/Release/net8.0/Acme.Billing.dll"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"outputDirectory"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"protected"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="nl"&gt;"rename"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"stringEncryption"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="nl"&gt;"metadata"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"compactHeaps"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"dedupeBlobs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"removeOrphanStrings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"renumberTokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the usual invocation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nebula protect --config nebula.config.json --out protected
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The one setting worth understanding is &lt;code&gt;renumberTokens&lt;/code&gt;. Leaving tokens as they were (only rebuilding heaps) is the conservative choice if something downstream pins a specific token — for example a tool that reads your assembly by hard-coded &lt;code&gt;MethodDef&lt;/code&gt; row. That is rare. Keep it &lt;code&gt;true&lt;/code&gt; unless you have a concrete reason, because renumbering is what lets empty table rows be dropped.&lt;/p&gt;

&lt;h3&gt;
  
  
  When to hold back
&lt;/h3&gt;

&lt;p&gt;Compaction is safe for ordinary assemblies, but two cases deserve a &lt;code&gt;metadata.preserve&lt;/code&gt; list. First, an assembly loaded by &lt;strong&gt;&lt;code&gt;mdToken&lt;/code&gt;&lt;/strong&gt; across a boundary — some profiling or instrumentation hosts cache tokens. Second, anything doing &lt;code&gt;Module.ResolveMethod(int metadataToken)&lt;/code&gt; on &lt;em&gt;itself&lt;/em&gt; with a literal token baked in source. Both are unusual; when they apply, pin the affected members:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"metadata"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"compactHeaps"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"renumberTokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"preserve"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"Acme.Billing.Diagnostics.TokenProbe.*"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Named members keep their original tokens; everything else is renumbered and compacted around them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it actually saves
&lt;/h2&gt;

&lt;p&gt;Numbers depend entirely on how name-heavy your assembly was, which is to say how much renaming removed. A representative result on a mid-size business assembly — ~4,200 methods, heavy domain vocabulary, strings encrypted — looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                           #Strings     #US      #Blob     File
rename only (no compaction)  412 KB   188 KB    96 KB    1.84 MB
+ heap compaction             34 KB     2 KB    71 KB    1.27 MB
                             ───────   ──────   ──────   ───────
                              -92%      -99%     -26%     -31%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;#Strings&lt;/code&gt; collapse is the orphaned original identifiers going away. The &lt;code&gt;#US&lt;/code&gt; collapse is the pre-encryption literals going away. &lt;code&gt;#Blob&lt;/code&gt; shrinks less and only from de-duplication, because signatures were all live. A 31% file reduction is typical for a rename-heavy assembly; a small utility with few members will see almost nothing, because there were few orphans to collect.&lt;/p&gt;

&lt;p&gt;Startup moves too, though less than size suggests. The runtime memory-maps metadata and reads it lazily, so a smaller &lt;code&gt;#Strings&lt;/code&gt; heap mostly helps cold start and working set rather than steady-state throughput. Treat the size win as the headline and the startup win as a bonus — and, as always, measure your own assembly rather than trusting a table.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verify it worked
&lt;/h2&gt;

&lt;p&gt;Two checks, both quick. First, confirm the orphans are gone with the same scan that exposed them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ strings protected/Acme.Billing.dll &lt;span class="o"&gt;|&lt;/span&gt; grep -i invoice
$    &lt;span class="c"&gt;# (no output — the original names are no longer in the file)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second, open the protected assembly in &lt;a href="https://delta1labs.com/products/glass" rel="noopener noreferrer"&gt;Glass.NET&lt;/a&gt; and look at the metadata view: the &lt;code&gt;#Strings&lt;/code&gt; heap should contain only short rename output and framework names, the &lt;code&gt;#US&lt;/code&gt; heap should be near-empty if you encrypted strings, and token navigation should resolve cleanly — a renumbering bug shows up immediately as a broken reference. Glass reads the heaps directly, so it is the honest way to confirm compaction did what the config asked without shipping first.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short version
&lt;/h2&gt;

&lt;p&gt;Renaming changes what metadata points at; compaction reclaims what it used to point at. Skip it and you ship an assembly whose original names are hidden from a decompiler but trivially recoverable with &lt;code&gt;strings&lt;/code&gt;, carrying hundreds of kilobytes of dead heap. Run it and the orphans are deleted, blobs de-duplicated, tokens re-packed, and the file is both smaller and genuinely scrubbed of the vocabulary you meant to hide. It is on by default when you rename for exactly that reason — leave it on, pin the rare self-referential token, and verify in Glass before you ship.&lt;/p&gt;

&lt;p&gt;See &lt;a href="https://delta1labs.com/products/nebula" rel="noopener noreferrer"&gt;Nebula.NET&lt;/a&gt; for the full transform pipeline and the &lt;code&gt;nebula.config.json&lt;/code&gt; reference, and &lt;a href="https://delta1labs.com/blog/dotnet-metadata-tables-explained/" rel="noopener noreferrer"&gt;metadata tables explained&lt;/a&gt; for the structures compaction operates on.&lt;/p&gt;

</description>
      <category>metadata</category>
      <category>nebula</category>
    </item>
    <item>
      <title>Build a tamper-evident license audit log with hash chaining in Keyright</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Sun, 15 Nov 2026 20:07:23 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/build-a-tamper-evident-license-audit-log-with-hash-chaining-in-keyright-3lk0</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/build-a-tamper-evident-license-audit-log-with-hash-chaining-in-keyright-3lk0</guid>
      <description>&lt;p&gt;An audit log is only worth as much as its weakest guarantee, and for a licensing system that guarantee is usually nothing at all. Most issuing services write a row per operation — &lt;em&gt;key issued&lt;/em&gt;, &lt;em&gt;seat claimed&lt;/em&gt;, &lt;em&gt;license revoked&lt;/em&gt; — and trust that nobody with access ever rewrites history. But the audit trail is exactly the record someone wants to edit: a reseller who over-issued, an insider who quietly re-activated a revoked key, a dispute where the question is &lt;em&gt;what did the server actually do, and when&lt;/em&gt;. If any party can delete or back-date a row without leaving a mark, the log proves nothing.&lt;/p&gt;

&lt;p&gt;This is a how-to for closing that gap. We will take Keyright's audit trail and make it &lt;strong&gt;tamper-evident&lt;/strong&gt; by chaining every entry to the cryptographic hash of the one before it. The result is a log where changing, reordering, or deleting any historical entry breaks every entry after it, and where you can prove to a third party that the record is intact — without trusting the storage, the operator, or the host.&lt;/p&gt;

&lt;h2&gt;
  
  
  What hash chaining buys you
&lt;/h2&gt;

&lt;p&gt;Tamper-&lt;em&gt;proof&lt;/em&gt; is the wrong word; storage can always be wiped. The achievable property is tamper-&lt;em&gt;evidence&lt;/em&gt;: any modification is detectable. Hash chaining delivers it with one rule. Each audit entry carries the hash of the previous entry's hash. Because a SHA-256 digest depends on every bit of its input, entry &lt;em&gt;N&lt;/em&gt;'s hash transitively commits to the entire history before it. Flip a byte in entry 5 and entry 5's hash changes, which invalidates entry 6's stored &lt;code&gt;prevHash&lt;/code&gt;, which changes entry 6's hash, and so on to the head. One verification pass over the chain catches a tamper anywhere in it.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
  &lt;br&gt;
    &lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  entry 41&lt;br&gt;
  prevHash: a7f3…&lt;br&gt;
  action: key.issued&lt;br&gt;
  subject: KR-9QX…&lt;br&gt;
  hash: 3c1b…&lt;br&gt;
  &lt;br&gt;
  entry 42&lt;br&gt;
  prevHash: 3c1b…&lt;br&gt;
  action: seat.claimed&lt;br&gt;
  subject: host-7e2&lt;br&gt;
  hash: 8e04…&lt;br&gt;
  &lt;br&gt;
  entry 43&lt;br&gt;
  prevHash: 8e04…&lt;br&gt;
  action: license.revoked&lt;br&gt;
  subject: KR-9QX…&lt;br&gt;
  hash: d55a…&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  each entry's hash becomes the next entry's prevHash — the chain seals the past&lt;br&gt;
&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1 — Enable the audit chain
&lt;/h2&gt;

&lt;p&gt;In your Keyright instance, the audit trail is written for every state-changing operation by default, but chaining is opt-in so that existing deployments are not forced to re-hash their history on upgrade. Turn it on in &lt;code&gt;keyright.config.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"audit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"chain"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"hashAlgorithm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"SHA-256"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"genesisLabel"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"acme-prod-2026"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;genesisLabel&lt;/code&gt; is folded into the very first entry's hash so two separate deployments that happen to log identical operations still produce different chains — it binds the chain to &lt;em&gt;this&lt;/em&gt; instance. On the next start, Keyright seals a genesis entry (&lt;code&gt;seq: 0&lt;/code&gt;) whose &lt;code&gt;prevHash&lt;/code&gt; is 32 zero bytes, and every subsequent operation extends from there. Community Edition includes the chained writer; what the paid tiers add is signed checkpointing, covered in Step 4.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 — Read the chain over the admin API
&lt;/h2&gt;

&lt;p&gt;Entries are exposed through the admin API in sequence order. Page forward with the &lt;code&gt;after&lt;/code&gt; cursor so you never have to pull the whole trail at once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="na"&gt;GET /v1/admin/audit?after&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;licensing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;internal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;acme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;
&lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bearer&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;admin&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"entries"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"seq"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"ts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-16T09:12:04.118Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"actor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"svc:fulfillment"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"key.issued"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"subject"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"KR-9QX2-7F3M-..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"payloadHash"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"sha256:1f0a9c..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"prevHash"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"sha256:a7f3e2..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"entryHash"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"sha256:3c1b88..."&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"head"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"seq"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;43&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"entryHash"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"sha256:d55a10..."&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two deliberate choices make this safe to hand around. The entry carries only a &lt;code&gt;payloadHash&lt;/code&gt;, not the payload itself — the full operation detail (licensee email, machine fingerprint) stays behind the admin boundary, so the verifiable record never leaks personal data. And the response echoes the current &lt;code&gt;head&lt;/code&gt;, which is the single value you need to detect a truncation attack: if entries vanish off the end, the head you remember will no longer match.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 — Verify the chain yourself
&lt;/h2&gt;

&lt;p&gt;Do not trust the server to tell you the chain is valid; recompute it. The only subtlety is that the hash must be taken over a &lt;strong&gt;canonical&lt;/strong&gt; byte encoding — the same bytes the server hashed — so field order and formatting are fixed, not left to a JSON serializer's whims. Keyright canonicalizes each entry as length-prefixed UTF-8 fields in a frozen order, then hashes &lt;code&gt;prevHash ‖ canonicalBytes&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Security&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Cryptography&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nc"&gt;Canonicalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AuditEntry&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Frozen field order. Each field is length-prefixed so that&lt;/span&gt;
    &lt;span class="c1"&gt;// ("ab","c") and ("a","bc") can never collide.&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ms&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MemoryStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTF8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Span&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;stackalloc&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;BinaryPrimitives&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteUInt32BigEndian&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Seq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CultureInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InvariantCulture&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Ts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"O"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CultureInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InvariantCulture&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// round-trip ISO-8601&lt;/span&gt;
    &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Actor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Subject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PayloadHash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nc"&gt;ComputeHash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;prevHash&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;AuditEntry&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sha&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;SHA256&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;sha&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TransformBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prevHash&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prevHash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Canonicalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;sha&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TransformFinalBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;sha&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Hash&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Walk the chain. Returns the seq of the first broken entry, or null if intact.&lt;/span&gt;
&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nc"&gt;FindBreak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IReadOnlyList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AuditEntry&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;genesisPrev&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;genesisPrev&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 32 zero bytes, or the hash of your last checkpoint&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// must be contiguous and ascending by seq&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ComputeHash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;CryptographicOperations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FixedTimeEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Convert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromHexString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EntryHash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Seq&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;FindBreak&lt;/code&gt; is the whole security model in twenty lines. Start from a &lt;code&gt;prevHash&lt;/code&gt; you already trust — the genesis zero-block the first time, or the hash of your last verified checkpoint on later runs — and recompute each entry's hash from the previous one. The first entry whose stored &lt;code&gt;entryHash&lt;/code&gt; does not match is the point of tampering, or the point where a row was deleted and the sequence no longer lines up. Note the length-prefixed fields: without them, an attacker could shuffle bytes between &lt;code&gt;actor&lt;/code&gt; and &lt;code&gt;action&lt;/code&gt; and leave the concatenation unchanged.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 — Anchor the head so deletion cannot hide
&lt;/h2&gt;

&lt;p&gt;Hash chaining catches edits and reordering, but not the honest-looking truncation where someone lops off the tail and nobody has a copy of what used to be there. The fix is to periodically publish the head hash somewhere the operator cannot silently rewrite — a &lt;strong&gt;checkpoint&lt;/strong&gt;. Keyright can emit one on a schedule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"audit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"chain"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"checkpoint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"everyMinutes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"sign"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A signed checkpoint is a tiny record — &lt;code&gt;{ seq, entryHash, ts }&lt;/code&gt; signed with your issuing key — that you forward out of the system: into a separate append-only store, a compliance mailbox, a counterparty's inbox. Once a counterparty holds a checkpoint saying &lt;em&gt;"at 10:00 the head was at seq 4,210 with hash d55a…"&lt;/em&gt;, no later deletion can take the trail below 4,210 without contradicting a signature they already have. The chain proves internal consistency; the checkpoint pins the chain to a point in wall-clock time that an outsider witnessed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5 — Verify in CI, not just by hand
&lt;/h2&gt;

&lt;p&gt;Make the verification a build step so a broken chain fails loudly instead of waiting for a dispute. The CLI pulls the range, recomputes it, and exits non-zero on the first mismatch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;$ keyright audit verify --from 0 --to head \
    --expect-checkpoint checkpoints/2026-11-16T10-00.json
Verifying 4211 entries from genesis…
  genesis label: acme-prod-2026
  checkpoint seq 4210 &lt;span class="nb"&gt;hash&lt;/span&gt; d55a10…  OK &lt;span class="o"&gt;(&lt;/span&gt;signature valid&lt;span class="o"&gt;)&lt;/span&gt;
Chain intact: 4211/4211 entries, head d55a10… at 2026-11-16T10:00:11Z
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A tampered trail produces the opposite, naming the first entry that fails so you know exactly where history was touched:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;$ keyright audit verify --from 0 --to head
Chain BROKEN at seq 42: stored &lt;span class="nb"&gt;hash&lt;/span&gt; 8e04a1… != computed 0b7cc9…
  entries 0–41 verify&lt;span class="o"&gt;;&lt;/span&gt; everything from 42 onward is unprovable
error: audit chain verification failed &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt; 2&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What legitimately breaks a chain
&lt;/h2&gt;

&lt;p&gt;A broken chain is not always an attack, and treating every break as a breach will teach your team to ignore the alert. Three benign causes are worth knowing. A &lt;strong&gt;schema migration&lt;/strong&gt; that adds a field to the canonical encoding will change every hash after it — which is why you start a fresh chain segment at the migration boundary and checkpoint the old head rather than re-hashing history in place. A &lt;strong&gt;restore from backup&lt;/strong&gt; that loses the entries written after the snapshot is a real gap, but an expected one; the checkpoint tells you precisely how many entries you are missing. And a &lt;strong&gt;clock that jumps backward&lt;/strong&gt; can make timestamps non-monotonic without breaking the hash at all — the chain commits to the order you wrote entries, not to honest time, which is exactly why wall-clock trust lives in the signed checkpoint and not in the &lt;code&gt;ts&lt;/code&gt; field.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Chaining turns a licensing audit trail from a set of editable rows into a record that defends itself. Enable the chain in config, read entries and the head over the admin API, recompute the chain with a twenty-line walk over a canonical encoding, and anchor the head with signed checkpoints so truncation cannot hide. The payoff is a trail you can hand to an auditor, a partner, or a court and prove, from first principles, that it has not been rewritten since the last point anyone witnessed it.&lt;/p&gt;

</description>
      <category>auditlog</category>
      <category>keyright</category>
    </item>
    <item>
      <title>Decompiling the `with` expression: how Glass.NET rebuilds record clone sites</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Sun, 15 Nov 2026 20:05:22 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/decompiling-the-with-expression-how-glassnet-rebuilds-record-clone-sites-53f4</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/decompiling-the-with-expression-how-glassnet-rebuilds-record-clone-sites-53f4</guid>
      <description>&lt;p&gt;A &lt;code&gt;with&lt;/code&gt; expression is one of the more magical-looking pieces of modern C#: you take an immutable record, write &lt;code&gt;original with { Price = 9.99m }&lt;/code&gt;, and get a fresh copy with one field changed and everything else intact. Non-destructive mutation. But there is no &lt;code&gt;with&lt;/code&gt; opcode, no "clone this but change that" instruction in the CLR. By the time the compiler is done, the whole expression has become a plain virtual method call followed by a few field stores. Rebuilding the &lt;code&gt;with&lt;/code&gt; keyword from that shape is a small, precise pattern-match — and it is a good way to see how &lt;a href="https://delta1labs.com/products/glass" rel="noopener noreferrer"&gt;Glass.NET&lt;/a&gt;, the free .NET decompiler, reconstructs language features that exist only as conventions in the metadata.&lt;/p&gt;

&lt;p&gt;This post walks one &lt;code&gt;with&lt;/code&gt; site all the way down to IL and back up to C#. If you want the mechanics of the &lt;em&gt;record declaration itself&lt;/em&gt; — &lt;code&gt;EqualityContract&lt;/code&gt;, value equality, &lt;code&gt;PrintMembers&lt;/code&gt; — that is a separate fingerprint; here we care only about the clone &lt;em&gt;call site&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The source
&lt;/h2&gt;

&lt;p&gt;Start with a tiny record and a single non-destructive update:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="nc"&gt;Price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Stock&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Catalog&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="nc"&gt;Discount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;newPrice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newPrice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Stock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stock&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Discount&lt;/code&gt; returns a new &lt;code&gt;Product&lt;/code&gt; that shares &lt;code&gt;Name&lt;/code&gt;, takes &lt;code&gt;newPrice&lt;/code&gt;, and decrements &lt;code&gt;Stock&lt;/code&gt; — without ever mutating &lt;code&gt;p&lt;/code&gt;. Two things have to happen under the hood: the object must be &lt;em&gt;copied&lt;/em&gt;, then the two named members must be &lt;em&gt;overwritten&lt;/em&gt; on the copy. That is exactly what the IL shows.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the compiler emits
&lt;/h2&gt;

&lt;p&gt;The record itself gains two synthesized members that make &lt;code&gt;with&lt;/code&gt; possible: a &lt;strong&gt;protected copy constructor&lt;/strong&gt; that clones every field, and a &lt;strong&gt;virtual clone method&lt;/strong&gt; the C# compiler names &lt;code&gt;&amp;lt;Clone&amp;gt;$&lt;/code&gt; (the angle brackets guarantee you can never collide with it in source). The clone method just calls the copy constructor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Synthesized on the record — shown here with readable names&lt;/span&gt;
&lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Name&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Price&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Stock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stock&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;virtual&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Clone&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;$&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;with&lt;/code&gt; expression in &lt;code&gt;Discount&lt;/code&gt; compiles to a &lt;code&gt;callvirt&lt;/code&gt; of &lt;code&gt;&amp;lt;Clone&amp;gt;$&lt;/code&gt;, then a store into each property named inside the braces. Here is the method body as &lt;code&gt;ildasm&lt;/code&gt;/Glass shows it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;hidebysig&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="nc"&gt;Discount&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;valuetype&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Decimal&lt;/span&gt; &lt;span class="n"&gt;newPrice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;cil&lt;/span&gt; &lt;span class="n"&gt;managed&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maxstack&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;locals&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="no"&gt;V_0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="no"&gt;IL_0000&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ldarg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;                       &lt;span class="c1"&gt;// p&lt;/span&gt;
    &lt;span class="no"&gt;IL_0001&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;callvirt&lt;/span&gt;   &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;Clone&amp;gt;$'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="no"&gt;IL_0006&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;stloc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;                        &lt;span class="c1"&gt;// V_0 = clone of p&lt;/span&gt;
    &lt;span class="no"&gt;IL_0007&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ldloc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="no"&gt;IL_0008&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ldarg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;                        &lt;span class="c1"&gt;// newPrice&lt;/span&gt;
    &lt;span class="no"&gt;IL_0009&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;callvirt&lt;/span&gt;   &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;set_Price&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;valuetype&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;IL_000e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ldloc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="nc"&gt;IL_000f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ldarg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;                        &lt;span class="c1"&gt;// p&lt;/span&gt;
    &lt;span class="no"&gt;IL_0010&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;callvirt&lt;/span&gt;   &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="n"&gt;int32&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get_Stock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="no"&gt;IL_0015&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ldc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="no"&gt;IL_0016&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sub&lt;/span&gt;
    &lt;span class="nc"&gt;IL_0017&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;callvirt&lt;/span&gt;   &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;set_Stock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;int32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;IL_001c&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ldloc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="nc"&gt;IL_001d&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ret&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read it top to bottom and the shape is unmistakable: &lt;strong&gt;one &lt;code&gt;callvirt&lt;/code&gt; to a method named &lt;code&gt;&amp;lt;Clone&amp;gt;$&lt;/code&gt;, its result parked in a temporary, then a sequence of property setter calls on that same temporary, and finally the temporary is returned.&lt;/strong&gt; The setters are &lt;code&gt;set_Price&lt;/code&gt; and &lt;code&gt;set_Stock&lt;/code&gt; — the init-only setters of the record, callable here because the copy constructor and &lt;code&gt;with&lt;/code&gt; lowering run in an initialization context.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pattern Glass keys on
&lt;/h2&gt;

&lt;p&gt;Glass does not look for a flag that says "this was a &lt;code&gt;with&lt;/code&gt;." There is no such flag. It matches the structural signature of the lowered expression:&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;br&gt;
Recognizing a &lt;code&gt;with&lt;/code&gt; expression in IL&lt;br&gt;
&lt;br&gt;
IL sequence&lt;br&gt;
callvirt &amp;lt;Clone&amp;gt;$()&lt;br&gt;
stloc V_0&lt;br&gt;
ldloc V_0&lt;br&gt;
... set_Price&lt;br&gt;
ldloc V_0&lt;br&gt;
... set_Stock&lt;br&gt;
ldloc V_0 ; ret&lt;br&gt;
&lt;br&gt;
Match test&lt;br&gt;
callee is compiler&lt;br&gt;
method named&lt;br&gt;
&amp;lt;Clone&amp;gt;$ ?&lt;br&gt;
temp only mutated&lt;br&gt;
by init setters?&lt;br&gt;
&lt;br&gt;
Reconstructed C#&lt;br&gt;
p with {&lt;br&gt;
  Price = newPrice,&lt;br&gt;
  Stock = p.Stock - 1&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
No &lt;code&gt;with&lt;/code&gt; opcode exists — the keyword is inferred from the clone-then-set shape.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The recognition rule, stated precisely, is: &lt;em&gt;a call to a synthesized &lt;code&gt;&amp;lt;Clone&amp;gt;$&lt;/code&gt; method whose result is stored in a temporary, where that temporary is subsequently mutated only through init-only setters (or direct field stores) before being used as a value.&lt;/em&gt; When that holds, the clone call plus the setter run collapse into a single &lt;code&gt;with&lt;/code&gt; expression; the receiver of &lt;code&gt;&amp;lt;Clone&amp;gt;$&lt;/code&gt; becomes the operand before &lt;code&gt;with&lt;/code&gt;, and each setter becomes one &lt;code&gt;Member = value&lt;/code&gt; entry inside the braces.&lt;/p&gt;
&lt;h2&gt;
  
  
  What Glass reconstructs
&lt;/h2&gt;

&lt;p&gt;Run it through the decompiler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;glass decompile Catalog.dll --type Catalog --member Discount
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Glass produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="nc"&gt;Discount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;newPrice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newPrice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Stock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stock&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the original source, down to the ordering of the initializer entries (Glass preserves the setter order from the IL, which is source order). The temporary &lt;code&gt;V_0&lt;/code&gt;, the &lt;code&gt;&amp;lt;Clone&amp;gt;$&lt;/code&gt; call, and the two &lt;code&gt;set_&lt;/code&gt; invocations have all disappeared into the keyword — which is the honest reconstruction, because that is precisely what the C# programmer wrote.&lt;/p&gt;

&lt;h3&gt;
  
  
  When the pattern does &lt;em&gt;not&lt;/em&gt; hold
&lt;/h3&gt;

&lt;p&gt;The value of a structural match is that it degrades honestly. If Glass sees a &lt;code&gt;&amp;lt;Clone&amp;gt;$&lt;/code&gt; call whose result is mutated in some way a &lt;code&gt;with&lt;/code&gt; block cannot express — for example a loop writing elements, a method call that is not an init setter, or branching between the clone and the stores — it does &lt;strong&gt;not&lt;/strong&gt; force a &lt;code&gt;with&lt;/code&gt;. It falls back to showing the literal clone call and the individual assignments, because inventing a &lt;code&gt;with&lt;/code&gt; there would be a lie about the control flow. You can see this yourself by passing &lt;code&gt;--no-pattern with&lt;/code&gt; to compare the raw lowered form against the reconstructed one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;glass decompile Catalog.dll --member Discount --no-pattern with
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="nc"&gt;Discount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="n"&gt;newPrice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Clone&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;$&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// raw: the clone call is explicit&lt;/span&gt;
    &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newPrice&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stock&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Seeing both forms side by side is useful when you are auditing an unfamiliar assembly — maybe your own release build with no PDB, or a third-party library you need to interop with — and want to confirm that a method really is doing a simple copy-and-set and not something subtler hiding behind a clone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Record structs: a different shape
&lt;/h2&gt;

&lt;p&gt;One wrinkle worth knowing. A &lt;code&gt;record struct&lt;/code&gt; has no &lt;code&gt;&amp;lt;Clone&amp;gt;$&lt;/code&gt; method, because value types are copied by assignment — there is nothing to call. For &lt;code&gt;readonly record struct Point(int X, int Y)&lt;/code&gt;, the &lt;code&gt;with&lt;/code&gt; expression lowers to a copy of the struct on the stack (a &lt;code&gt;ldobj&lt;/code&gt;/&lt;code&gt;stloc&lt;/code&gt; of the whole value, or simply a fresh local initialized from the source) followed by the same init-setter run. Glass recognizes &lt;em&gt;that&lt;/em&gt; shape too: a value-type copy of a record struct followed by init-only setters is the struct flavor of &lt;code&gt;with&lt;/code&gt;, and it reconstructs the identical &lt;code&gt;source with { … }&lt;/code&gt; syntax. The signal differs — a struct copy instead of a &lt;code&gt;callvirt &amp;lt;Clone&amp;gt;$()&lt;/code&gt; — but the reconstruction rule is the same: copy, then overwrite named members, then use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters for reading real code
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;with&lt;/code&gt; expressions are everywhere in modern C#: configuration objects threaded through a pipeline, state updates in a reducer, DTOs copied with one field adjusted. When you decompile such code without recognition you get a thicket of &lt;code&gt;&amp;lt;Clone&amp;gt;$()&lt;/code&gt; temporaries and scattered setters that obscures the single intention behind each one — &lt;em&gt;make a copy with these changes&lt;/em&gt;. Collapsing that back to &lt;code&gt;with&lt;/code&gt; is the difference between reading someone's design and reading the compiler's bookkeeping.&lt;/p&gt;

&lt;p&gt;Glass is a free, static-only decompiler built for exactly this kind of understanding — your own assemblies, your dependencies, your legacy builds. It reads IL to C#; it does not run, patch, or modify anything. Point it at a DLL in the Visual-Studio-native UI, the CLI, or over &lt;a href="https://delta1labs.com/products/glass" rel="noopener noreferrer"&gt;MCP&lt;/a&gt; and the &lt;code&gt;with&lt;/code&gt; keyword comes back wherever the clone-then-set shape says it should.&lt;/p&gt;

</description>
      <category>decompilation</category>
      <category>glass</category>
    </item>
    <item>
      <title>Conditional license refresh with ETag: stop re-downloading a license that has not changed</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Sun, 15 Nov 2026 17:07:29 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/conditional-license-refresh-with-etag-stop-re-downloading-a-license-that-has-not-changed-34c</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/conditional-license-refresh-with-etag-stop-re-downloading-a-license-that-has-not-changed-34c</guid>
      <description>&lt;p&gt;A Keyright client does not call home on every license check. It activates once, caches the signed lease, and from then on every &lt;code&gt;Validate()&lt;/code&gt; is a local, offline operation against the embedded public key. What &lt;em&gt;does&lt;/em&gt; talk to the issuing service is the background refresh: on a timer — typically every few minutes to a few hours — the SDK re-fetches the lease so that a renewal, an entitlement change, or a revocation is picked up without waiting for a restart.&lt;/p&gt;

&lt;p&gt;Here is the thing about that refresh loop: almost every iteration of it is a no-op. A license is a slow-moving resource. It changes when someone renews, upgrades, transfers a seat, or gets revoked — events that happen days or weeks apart. Between those events, a client that refreshes every five minutes asks the service "what is the current state of this license?" hundreds of times and gets back byte-for-byte the same signed lease every single time. Each of those answers is a full response body the service serialized and signed, pushed over the network, that the client then base64-decoded and ran an RSA verify over — all to confirm what it already knew.&lt;/p&gt;

&lt;p&gt;HTTP has had the right primitive for this since 1999. It is the &lt;strong&gt;conditional GET&lt;/strong&gt;, built on the &lt;code&gt;ETag&lt;/code&gt; response header and the &lt;code&gt;If-None-Match&lt;/code&gt; request header, and wiring it into the refresh path turns the common case — nothing changed — into a headers-only round trip that returns &lt;code&gt;304 Not Modified&lt;/code&gt; with an empty body.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaway:&lt;/strong&gt; Have your issuing service stamp every license response with a strong &lt;code&gt;ETag&lt;/code&gt; derived from the license's version and signature. Have the SDK remember that tag and send it back as &lt;code&gt;If-None-Match&lt;/code&gt; on the next refresh. When nothing has changed the service answers &lt;code&gt;304 Not Modified&lt;/code&gt; with no body, the client keeps its cached lease untouched, and you have replaced a full signed-payload download plus a signature verify with a few hundred bytes of headers — without ever letting a stale cache hide a revocation.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a license fetch looks like today
&lt;/h2&gt;

&lt;p&gt;Strip the SDK away and a refresh is an ordinary HTTP GET. The client asks for the current lease for a key; the service returns the signed document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;licenses&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;keyright&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Keyright&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;acme&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;suite&lt;/span&gt;
&lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bearer&lt;/span&gt; &lt;span class="no"&gt;AK&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9f3c&lt;/span&gt;…            ← &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;activation&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;initial&lt;/span&gt; &lt;span class="n"&gt;handshake&lt;/span&gt;

&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="no"&gt;OK&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;vnd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keyright&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lease&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1184&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"lease"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"eyJhbGciOi…"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"signature"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"MEUCIQ…"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"edition"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"pro"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"expiresAt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2027-01-01T00:00:00Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;lease&lt;/code&gt; blob is the canonical, signed payload the client verifies offline. At a kilobyte-plus a shot, times a fleet of clients, times a refresh every few minutes, times the fact that the content is identical between license events, it is pure waste. The service did real work to produce a body nobody needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ETag: a fingerprint the client can quote back
&lt;/h2&gt;

&lt;p&gt;An &lt;code&gt;ETag&lt;/code&gt; ("entity tag") is an opaque validator the server attaches to a response. Its only contract is this: if two responses for the same URL carry the same &lt;code&gt;ETag&lt;/code&gt;, their representations are identical; if the resource changes, the &lt;code&gt;ETag&lt;/code&gt; must change. The client treats it as a black box — it never parses it — and simply quotes it back on the next request to ask "do you still have exactly this?".&lt;/p&gt;

&lt;p&gt;For a license, you do not want to hash the whole response body to produce the tag (that works, but it costs a hash over the payload on every request). You already have two fields that change if and only if the license changes: a monotonic &lt;strong&gt;version&lt;/strong&gt; the issuing service bumps on every mutation, and the &lt;strong&gt;signature&lt;/strong&gt; itself. Combine them into a strong validator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="nc"&gt;ETag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"v47-3b9a1f"&lt;/span&gt;      ← &lt;span class="n"&gt;license&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="mi"&gt;47&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;signature&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;strong&lt;/span&gt; &lt;span class="n"&gt;tag&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a &lt;strong&gt;strong&lt;/strong&gt; ETag (no &lt;code&gt;W/&lt;/code&gt; prefix), which is the correct choice here: a conditional request should match only when the bytes are genuinely identical, because the client is going to &lt;em&gt;skip verifying a new signature&lt;/em&gt; on a match. A weak tag (&lt;code&gt;W/"…"&lt;/code&gt;), which only promises semantic equivalence, is wrong for this — "semantically equivalent" is not good enough when the difference might be a revocation.&lt;/p&gt;

&lt;p&gt;The service computes the tag from fields it already has in hand, so tagging a response is essentially free, and crucially the tag changes the instant anything about the license does: a renewal bumps the version, a revocation bumps the version, an entitlement edit bumps the version.&lt;/p&gt;

&lt;h2&gt;
  
  
  The conditional GET: If-None-Match turns a refresh into a 304
&lt;/h2&gt;

&lt;p&gt;Once the client has seen an &lt;code&gt;ETag&lt;/code&gt;, the next refresh sends it in an &lt;code&gt;If-None-Match&lt;/code&gt; header. The semantics are precise: "return the full resource &lt;em&gt;only if&lt;/em&gt; its current ETag does not match any of these; otherwise tell me it is unchanged."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;licenses&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;keyright&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Keyright&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;acme&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;suite&lt;/span&gt;
&lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bearer&lt;/span&gt; &lt;span class="no"&gt;AK&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9f3c&lt;/span&gt;…
&lt;span class="nc"&gt;If&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;None&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"v47-3b9a1f"&lt;/span&gt;             ← &lt;span class="no"&gt;I&lt;/span&gt; &lt;span class="n"&gt;already&lt;/span&gt; &lt;span class="n"&gt;have&lt;/span&gt; &lt;span class="n"&gt;exactly&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;do&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;still&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;

&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;304&lt;/span&gt; &lt;span class="nc"&gt;Not&lt;/span&gt; &lt;span class="nc"&gt;Modified&lt;/span&gt;
&lt;span class="nc"&gt;ETag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"v47-3b9a1f"&lt;/span&gt;
&lt;span class="na"&gt;Cache-Control: max-age&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No body. The client reads the &lt;code&gt;304&lt;/code&gt;, understands "my cached lease is still current," resets its refresh timer, and does nothing else — no decode, no signature verify, no state change. When the license &lt;em&gt;has&lt;/em&gt; changed, the match fails and the service answers exactly as before, with a &lt;code&gt;200&lt;/code&gt;, the new body, and a new &lt;code&gt;ETag&lt;/code&gt; the client stores for next time.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing conditional refresh in the SDK client
&lt;/h2&gt;

&lt;p&gt;If you are consuming the Keyright client through the typed-client registration, conditional requests are something you add in the refresh path — the SDK stores the last ETag alongside the cached lease and sends it on the next poll. Here is the shape of that handler, written against &lt;code&gt;HttpClient&lt;/code&gt; so the mechanics are explicit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ConditionalLeaseFetcher&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HttpClient&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// The validator the service last gave us, held next to the cached lease.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;_etag&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;SignedLease&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;_cached&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;RefreshResult&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;RefreshAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CancellationToken&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HttpRequestMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HttpMethod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/v1/licenses/current"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Quote the stored tag back. EntityTagHeaderValue parses the quoted form for us.&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_etag&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IfNoneMatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;EntityTagHeaderValue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_etag&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SendAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HttpCompletionOption&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ResponseHeadersRead&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StatusCode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;HttpStatusCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NotModified&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// The common case: the body is empty by spec. Keep what we have, untouched.&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;RefreshResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Unchanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_cached&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EnsureSuccessStatusCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// 200: a genuinely new representation. Only now do we pay for decode + verify.&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadFromJsonAsync&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;LeaseResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KeyrightException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"empty lease body"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;lease&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SignedLease&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;VerifyAndParse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_publicKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// RSA verify happens here&lt;/span&gt;

        &lt;span class="n"&gt;_cached&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;_etag&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ETag&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// store the new validator for next time&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;RefreshResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Updated&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lease&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two branches are the whole point. A &lt;code&gt;304&lt;/code&gt; returns &lt;code&gt;RefreshResult.Unchanged&lt;/code&gt; and never touches the signature path — the single most expensive thing a refresh can do is the one thing the fast path skips. A &lt;code&gt;200&lt;/code&gt; is treated exactly as an uncached fetch would be: verify, swap the cache, store the fresh ETag. There is no third state to get wrong.&lt;/p&gt;

&lt;p&gt;Notice &lt;code&gt;HttpCompletionOption.ResponseHeadersRead&lt;/code&gt;: on a &lt;code&gt;304&lt;/code&gt; there is no body to buffer, so you want to inspect the status from the headers before deciding whether to read content at all.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do not let max-age replace the local evaluation
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Cache-Control: max-age=300&lt;/code&gt; on the response tells the client it may serve the cached lease without re-asking for up to five minutes — that is what sets the floor on your refresh interval. What it must &lt;strong&gt;not&lt;/strong&gt; do is suppress the local, time-dependent part of a license check. A lease can carry an &lt;code&gt;expiresAt&lt;/code&gt; that falls &lt;em&gt;inside&lt;/em&gt; the max-age window; the moment the wall clock passes it, the entitlement is gone even though the cached bytes are still "fresh" by HTTP's definition. This is the same split covered in the hot-path caching work: cache the &lt;em&gt;signature verification&lt;/em&gt; (the ETag protects that), never cache the &lt;em&gt;evaluation at the current instant&lt;/em&gt;. &lt;code&gt;Validate()&lt;/code&gt; always re-evaluates expiry against the validated clock, no matter how fresh the HTTP cache believes the representation to be.&lt;/p&gt;

&lt;h2&gt;
  
  
  The correctness rule that makes this safe
&lt;/h2&gt;

&lt;p&gt;A conditional request is only as safe as the guarantee that the ETag changes whenever the license does. Get that wrong and a &lt;code&gt;304&lt;/code&gt; becomes a lie — the client holds a lease the service has already revoked and keeps answering &lt;code&gt;304&lt;/code&gt; because the tag never moved. So the rule on the service side is absolute:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Any mutation that changes what the license grants must change the ETag.&lt;/strong&gt; Because the tag is derived from the monotonic version, and every mutation bumps the version, this falls out for free — a revocation increments the version like any other edit, the next &lt;code&gt;If-None-Match&lt;/code&gt; fails to match, and the client gets a &lt;code&gt;200&lt;/code&gt; carrying the now-revoked state (which resolves to the Community Edition fallback on verify). There is no path where a live license change is masked by a stale tag, provided the version is the single source of truth and the tag is strong, not weak.&lt;/p&gt;

&lt;p&gt;The reverse failure — the tag changing when the license did &lt;em&gt;not&lt;/em&gt; — is harmless. It just means an occasional unnecessary &lt;code&gt;200&lt;/code&gt;, the same cost you were paying on every request before. Conditional requests degrade toward "download the whole thing," never toward "serve something stale."&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing it with curl
&lt;/h2&gt;

&lt;p&gt;You can watch the whole exchange from the command line, which is the fastest way to confirm your service is tagging correctly before you touch the SDK. First fetch captures the tag; the second sends it back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;$ curl -s -D - -H &lt;span class="s2"&gt;"Authorization: Bearer AK-9f3c…"&lt;/span&gt; \
       https://keyright.example.com/v1/licenses/current -o /dev/null &lt;span class="o"&gt;|&lt;/span&gt; grep -i etag
ETag: &lt;span class="s2"&gt;"v47-3b9a1f"&lt;/span&gt;

$ curl -s -D - -H &lt;span class="s2"&gt;"Authorization: Bearer AK-9f3c…"&lt;/span&gt; \
       -H &lt;span class="s1"&gt;'If-None-Match: "v47-3b9a1f"'&lt;/span&gt; \
       https://keyright.example.com/v1/licenses/current -o /dev/null &lt;span class="o"&gt;|&lt;/span&gt; head -1
HTTP/1.1 304 Not Modified
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;code&gt;304&lt;/code&gt; on the second call proves the round trip works. Now force a change — renew the license, or bump its version in your test harness — and repeat the conditional call: you should get a &lt;code&gt;200&lt;/code&gt;, a new body, and a &lt;em&gt;different&lt;/em&gt; ETag. If you get a &lt;code&gt;200&lt;/code&gt; with the &lt;em&gt;same&lt;/em&gt; ETag, your tag is not derived from a field that actually changed; if you get a &lt;code&gt;304&lt;/code&gt; after a revocation, your revocation path is not bumping the version, which is a correctness bug, not a caching one.&lt;/p&gt;

&lt;h3&gt;
  
  
  One gotcha: proxies and header stripping
&lt;/h3&gt;

&lt;p&gt;If your clients reach the issuing service through a reverse proxy or CDN, confirm it forwards &lt;code&gt;If-None-Match&lt;/code&gt; upstream and does not answer the conditional request itself from a cache that is unaware of revocation. A licensing response should be marked &lt;code&gt;Cache-Control: private&lt;/code&gt; precisely so that shared caches do not store it; the conditional validation belongs between the client and the issuing service, not in an intermediary that has no idea a license was pulled. Keep the validator end-to-end and the 304 means exactly what you think it means.&lt;/p&gt;

&lt;p&gt;That is the whole mechanism. The refresh loop still runs on its timer, still picks up every renewal and revocation on schedule, and still verifies every genuinely new lease — but the overwhelmingly common case, "nothing changed since I last asked," now costs a few hundred bytes of headers and a status-line read instead of a signed-payload download and a public-key verify. The license did not change, so the client does not do the work of pretending it might have.&lt;/p&gt;

</description>
      <category>caching</category>
      <category>keyright</category>
    </item>
    <item>
      <title>Decompiling file-local types: recovering the file modifier from a mangled metadata name</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Sun, 15 Nov 2026 17:04:40 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/decompiling-file-local-types-recovering-the-file-modifier-from-a-mangled-metadata-name-bk5</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/decompiling-file-local-types-recovering-the-file-modifier-from-a-mangled-metadata-name-bk5</guid>
      <description>&lt;p&gt;C# 11 added the &lt;code&gt;file&lt;/code&gt; access modifier: a type declared &lt;code&gt;file class Parser&lt;/code&gt; is visible only inside the single source file that declares it. Two files in the same project — or two source-generated files that each emit a helper — can both declare a &lt;code&gt;file class Parser&lt;/code&gt; without colliding, and neither can be touched from anywhere else. It exists mostly for the benefit of source generators, which emit support types into a user's compilation and must not leak names that clash with the user's own code or with another generator's.&lt;/p&gt;

&lt;p&gt;From a decompiler's point of view &lt;code&gt;file&lt;/code&gt; is an interesting problem because, like several recent C# features, &lt;strong&gt;it leaves no attribute behind&lt;/strong&gt;. There is no &lt;code&gt;[FileLocal]&lt;/code&gt; marker, no custom modifier, no flag in the &lt;code&gt;TypeDef&lt;/code&gt; row that says "this type was declared &lt;code&gt;file&lt;/code&gt;." The compiler encodes the modifier in the one place that survives into metadata and is guaranteed unique: &lt;strong&gt;the type's name&lt;/strong&gt;. It mangles the declared name into a form that is deliberately not a legal C# identifier, and it drops the visibility down to assembly-internal. A decompiler that reads the &lt;code&gt;TypeDef&lt;/code&gt; table and prints what it finds will emit a type called &lt;code&gt;&amp;lt;Validators&amp;gt;F0__Parser&lt;/code&gt; with &lt;code&gt;internal&lt;/code&gt; accessibility — which is neither what the author wrote nor anything the C# compiler will accept. Reconstructing the original means recognising the mangling, reversing it, and putting the recovered type back in a file bucket.&lt;/p&gt;

&lt;p&gt;This post walks the full round trip: the source, the metadata the compiler emits, and the C# Glass.NET reconstructs.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What the author wrote
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;file&lt;/code&gt; type usually keeps a small helper private to one file. Here &lt;code&gt;Validators.cs&lt;/code&gt; has a file-local rule plus a public façade that uses it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Validators.cs&lt;/span&gt;
&lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PhoneRule&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;IsValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Contact&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;Check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;PhoneRule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;PhoneRule&lt;/code&gt; is &lt;code&gt;file&lt;/code&gt;-scoped, so nothing outside &lt;code&gt;Validators.cs&lt;/code&gt; can name it — not another file in the same assembly, not a consumer referencing the DLL. &lt;code&gt;Contact&lt;/code&gt;, declared normally, calls it freely because it lives in the same file.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the compiler emits
&lt;/h2&gt;

&lt;p&gt;Two things happen to &lt;code&gt;PhoneRule&lt;/code&gt; on the way to metadata. First, its name is &lt;strong&gt;mangled&lt;/strong&gt;. The compiler builds a metadata name from a &lt;em&gt;file identifier&lt;/em&gt; (derived from the source file's name), an ordinal that disambiguates files that happen to share a name, and the declared type name, wrapped so the result cannot be written in source:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nf"&gt;private&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="n"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;ansi&lt;/span&gt; &lt;span class="n"&gt;beforefieldinit&lt;/span&gt;
       &lt;span class="s1"&gt;'&amp;lt;Validators&amp;gt;F0__PhoneRule'&lt;/span&gt;
       &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;hidebysig&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt;
          &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;IsValid&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;cil&lt;/span&gt; &lt;span class="n"&gt;managed&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ldarg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;callvirt&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="n"&gt;int32&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get_Length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;ldc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
    &lt;span class="n"&gt;ceq&lt;/span&gt;
    &lt;span class="n"&gt;ret&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note what is &lt;em&gt;not&lt;/em&gt; there: no &lt;code&gt;CompilerGeneratedAttribute&lt;/code&gt;, no custom attribute of any kind announcing the modifier. The &lt;code&gt;&amp;lt;Validators&amp;gt;F0__PhoneRule&lt;/code&gt; name is the entire record of the &lt;code&gt;file&lt;/code&gt; keyword. The &lt;code&gt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&lt;/code&gt; are the tell — they are reserved exactly so that user code can never produce an identifier that collides with a compiler-synthesized one.&lt;/p&gt;

&lt;p&gt;Second, the type's &lt;strong&gt;accessibility drops to assembly-internal&lt;/strong&gt;. A top-level type can only be &lt;code&gt;public&lt;/code&gt; or internal in the CLI type system — there is no finer-grained visibility at the metadata level — so the compiler emits &lt;code&gt;PhoneRule&lt;/code&gt; as internal and relies on the unspeakable name to enforce the stronger "one file only" rule at &lt;em&gt;compile&lt;/em&gt; time. In ILDasm a top-level internal type reads as &lt;code&gt;.class private&lt;/code&gt;, which is why the row above says &lt;code&gt;private&lt;/code&gt; even though you never wrote &lt;code&gt;private&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The call site inside &lt;code&gt;Contact.Check&lt;/code&gt; references the mangled name directly, because by the time IL is emitted the only name &lt;code&gt;PhoneRule&lt;/code&gt; has is the mangled one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight llvm"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;hidebysig&lt;/span&gt; &lt;span class="n"&gt;static&lt;/span&gt; &lt;span class="n"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;Check&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;cil&lt;/span&gt; &lt;span class="n"&gt;managed&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;ldarg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="k"&gt;call&lt;/span&gt; &lt;span class="n"&gt;bool&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;Validators&amp;gt;F0__PhoneRule'&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;IsValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;ret&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every reference to a file-local type inside its own file — base types, field types, method calls, &lt;code&gt;typeof&lt;/code&gt; — carries this mangled token. And because the C# rules forbid a file-local type from appearing in the signature of a non-file member, the mangled token is &lt;em&gt;guaranteed&lt;/em&gt; to appear only within the types that came from the same source file. That bound matters for reconstruction: Glass never has to chase a mangled reference across a file boundary.&lt;/p&gt;

&lt;h2&gt;
  
  
  The naive decompilation, and why it fails
&lt;/h2&gt;

&lt;p&gt;A decompiler that walks the &lt;code&gt;TypeDef&lt;/code&gt; table and renders each row literally produces this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;internal&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Validators&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;F0__PhoneRule&lt;/span&gt;   &lt;span class="c1"&gt;// will not compile&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;IsValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is wrong on two counts. The name &lt;code&gt;&amp;lt;Validators&amp;gt;F0__PhoneRule&lt;/code&gt; is not a legal identifier, so the file does not even parse. And &lt;code&gt;internal&lt;/code&gt; is the &lt;em&gt;metadata&lt;/em&gt; accessibility, not the source modifier the author chose — re-emitting &lt;code&gt;internal&lt;/code&gt; discards the &lt;code&gt;file&lt;/code&gt; intent entirely and, worse, would make the type visible to the whole assembly if you could somehow rename it, changing the program's meaning. A faithful decompiler has to undo both transformations together.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Glass.NET reads it back
&lt;/h2&gt;

&lt;p&gt;Glass treats the mangled name as a structured token rather than an opaque string. Its reconstruction of a type name runs a small decoder:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A top-level type whose name matches &lt;code&gt;&amp;lt;&lt;/code&gt; &lt;em&gt;file&lt;/em&gt; &lt;code&gt;&amp;gt;F&lt;/code&gt; &lt;em&gt;ordinal&lt;/em&gt; &lt;code&gt;__&lt;/code&gt; &lt;em&gt;name&lt;/em&gt; is a &lt;strong&gt;file-local type&lt;/strong&gt;. Glass splits it into the file identifier (&lt;code&gt;Validators&lt;/code&gt;), the ordinal (&lt;code&gt;0&lt;/code&gt;), and the declared name (&lt;code&gt;PhoneRule&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;The declared name is restored as the type's source identifier, so &lt;code&gt;PhoneRule&lt;/code&gt; appears exactly as written.&lt;/li&gt;
&lt;li&gt;The modifier is reconstructed as &lt;code&gt;file&lt;/code&gt;, &lt;strong&gt;not&lt;/strong&gt; the &lt;code&gt;internal&lt;/code&gt; the metadata reports — the mangled shape is stronger evidence of the author's intent than the assembly-level accessibility, which the compiler was forced to use only because no narrower one exists at the metadata layer.&lt;/li&gt;
&lt;li&gt;Every mangled reference to this type elsewhere in the assembly — the &lt;code&gt;call '&amp;lt;Validators&amp;gt;F0__PhoneRule'::IsValid&lt;/code&gt; inside &lt;code&gt;Contact&lt;/code&gt;, any field or base-type use — is rewritten to the restored &lt;code&gt;PhoneRule&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The file identifier is more than decoration. When Glass lays source back out, it uses the &lt;code&gt;&amp;lt;Validators&amp;gt;&lt;/code&gt; bucket to group every type that shares it, so file-local types land together in a recovered file that reflects their original grouping — and, critically, two different source files that each declared a &lt;code&gt;file class Parser&lt;/code&gt; (distinct mangled names, &lt;code&gt;&amp;lt;Validators&amp;gt;F0__Parser&lt;/code&gt; and &lt;code&gt;&amp;lt;Rules&amp;gt;F0__Parser&lt;/code&gt;) are reconstructed into &lt;em&gt;separate&lt;/em&gt; files, which is the only arrangement that compiles. Collapsing them into one file would reintroduce the name clash the &lt;code&gt;file&lt;/code&gt; modifier was invented to prevent.&lt;/p&gt;

&lt;p&gt;The reconstructed source round-trips cleanly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Glass groups this type into a recovered file keyed by its file identifier&lt;/span&gt;
&lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PhoneRule&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;IsValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Contact&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;Check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;PhoneRule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsValid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;file&lt;/code&gt; modifier is back, the mangled name is gone from both the declaration and the call site, and the public &lt;code&gt;Contact&lt;/code&gt; façade reads exactly as it did in source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Doing it from the CLI
&lt;/h2&gt;

&lt;p&gt;Point Glass at the assembly and let it reconstruct the whole thing, file grouping and all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Reconstruct to a source tree; file-local types are regrouped by file identifier&lt;/span&gt;
glass decompile Validators.dll -o ./recovered

&lt;span class="c"&gt;# Inspect a single type, mangled name and all&lt;/span&gt;
glass decompile Validators.dll --type PhoneRule
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you want to see the raw metadata the decoder is working from — the &lt;code&gt;.class private&lt;/code&gt; row with the &lt;code&gt;&amp;lt;Validators&amp;gt;F0__PhoneRule&lt;/code&gt; name and the mangled &lt;code&gt;call&lt;/code&gt; token — drop to the IL view:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;glass il Validators.dll --type &lt;span class="s2"&gt;"&amp;lt;Validators&amp;gt;F0__PhoneRule"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Seeing the mangled name beside the recovered &lt;code&gt;file class&lt;/code&gt; is the clearest way to understand what the modifier actually costs at the metadata layer: nothing but a naming convention and a dropped accessibility, reconstructed by reading the convention back.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this matters
&lt;/h2&gt;

&lt;p&gt;File-local types show up most often in generated code, which is exactly the code you are most likely to be reading in a decompiler — you have a DLL, a source generator ran during its build, and you want to understand what it produced. If your tool prints &lt;code&gt;internal class &amp;lt;Thing&amp;gt;F0__Helper&lt;/code&gt;, you learn almost nothing and you cannot recompile what you see. Recovering the real &lt;code&gt;file class Helper&lt;/code&gt;, grouped the way the generator emitted it, turns an unreadable mangled dump back into the code that was actually written — which is the whole point of decompiling your own or a third-party assembly to understand, debug, or interoperate with it.&lt;/p&gt;

&lt;p&gt;Glass.NET is a free .NET decompiler with a Visual Studio-native Avalonia UI and a CLI/MCP interface, built to reconstruct exactly these modern C# constructs — the ones that live in metadata conventions rather than in attributes — so what you read back is the source, not the compiler's bookkeeping.&lt;/p&gt;

</description>
      <category>filelocaltypes</category>
      <category>glass</category>
    </item>
    <item>
      <title>SuppressIldasmAttribute is not protection: what anti-ILDASM actually buys you</title>
      <dc:creator>Zero Heartbeat</dc:creator>
      <pubDate>Sun, 15 Nov 2026 17:03:26 +0000</pubDate>
      <link>https://dev.to/zero_heartbeat_06a3625d7a/suppressildasmattribute-is-not-protection-what-anti-ildasm-actually-buys-you-2bmk</link>
      <guid>https://dev.to/zero_heartbeat_06a3625d7a/suppressildasmattribute-is-not-protection-what-anti-ildasm-actually-buys-you-2bmk</guid>
      <description>&lt;p&gt;Search "protect .NET assembly" and someone will tell you to add one line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;assembly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CompilerServices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SuppressIldasm&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The promise is that your DLL can no longer be disassembled. The reality is narrower than almost anyone who pastes that line realises, and on modern .NET it does &lt;strong&gt;nothing at all&lt;/strong&gt;. This is a deep explainer on what &lt;code&gt;SuppressIldasmAttribute&lt;/code&gt; actually does, why it stops exactly one program, and what it takes to make an assembly genuinely expensive to read.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the attribute really is
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;SuppressIldasmAttribute&lt;/code&gt; is not encryption, not a permission, not a lock. It is a &lt;strong&gt;marker&lt;/strong&gt; — a zero-field custom attribute that the compiler writes into your assembly's metadata. At the IL level it is just another &lt;code&gt;.custom&lt;/code&gt; entry in the &lt;code&gt;CustomAttribute&lt;/code&gt; table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.custom instance void [System.Runtime]
    System.Runtime.CompilerServices.SuppressIldasmAttribute::.ctor() = ( 01 00 00 00 )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;( 01 00 00 00 )&lt;/code&gt; is the attribute blob: a two-byte prolog and a two-byte count, with no arguments. Nothing about your code changes. Every type, every method body, every string literal is written to the file exactly as before. The only new thing in the assembly is a flag that says, in effect, &lt;em&gt;"please don't disassemble me."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Whether anyone honours that request is entirely up to the tool reading the file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exactly one tool ever listened — and it stopped
&lt;/h2&gt;

&lt;p&gt;Historically, Microsoft's own &lt;code&gt;ildasm.exe&lt;/code&gt; — the IL Disassembler shipped with the .NET Framework SDK — checked for this attribute. If it found one, it printed &lt;code&gt;// This assembly is protected...&lt;/code&gt; and refused to dump the IL. That is the entire mechanism. It was a gentleman's agreement between Microsoft's authoring tool and Microsoft's disassembling tool.&lt;/p&gt;

&lt;p&gt;Two facts collapse the protection:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No other reader ever checked it.&lt;/strong&gt; ILSpy, dnSpy, dotPeek, JustDecompile, the Mono &lt;code&gt;monodis&lt;/code&gt; utility, and modern decompilers including Glass.NET read the metadata tables directly. None of them consult the &lt;code&gt;SuppressIldasm&lt;/code&gt; flag, because nothing in the ECMA-335 format obliges them to. They open the file, walk the &lt;code&gt;TypeDef&lt;/code&gt; and &lt;code&gt;MethodDef&lt;/code&gt; tables, resolve each method's IL from its RVA, and reconstruct C#. The attribute is invisible to them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;On .NET 6 and later, even ildasm ignores it.&lt;/strong&gt; The honour was removed. The attribute still compiles — it is marked obsolete — but the modern disassembler dumps the assembly regardless. So on any current .NET target, &lt;code&gt;[assembly: SuppressIldasm]&lt;/code&gt; is a literal no-op: it changes four bytes of metadata and protects nothing, not even against the one tool it was written for.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The net effect, today: you have added an attribute that does nothing, and possibly convinced yourself you are protected when you are not. That second part is the real hazard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it was always weak: the file is still readable
&lt;/h2&gt;

&lt;p&gt;Step back from the attribute and look at what a .NET assembly actually exposes. The managed metadata is not an opaque blob — it is a set of well-defined &lt;strong&gt;streams&lt;/strong&gt; inside the PE file, and decompilers feed on them directly.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;/p&gt;
What a decompiler reads from the metadata streams — the SuppressIldasm flag guards none of it
&lt;br&gt;
Assembly metadata a decompiler walks directly&lt;br&gt;
&lt;br&gt;
#~  (tables)&lt;br&gt;
TypeDef, MethodDef,&lt;br&gt;
Field, Param rows&lt;br&gt;
&lt;br&gt;
#Strings&lt;br&gt;
every type, method&lt;br&gt;
and field name&lt;br&gt;
&lt;br&gt;
#US&lt;br&gt;
every string literal&lt;br&gt;
in your code&lt;br&gt;
&lt;br&gt;
method bodies (IL)&lt;br&gt;
resolved from each RVA&lt;br&gt;
&lt;br&gt;
#Blob&lt;br&gt;
signatures, constants&lt;br&gt;
&lt;br&gt;
SuppressIldasm flag — one row in CustomAttribute&lt;br&gt;
The flag sits beside the data; it does not encrypt, remove or guard any of it.&lt;br&gt;
A reader that skips the flag still reads every box above.&lt;br&gt;


&lt;p&gt;The &lt;code&gt;#Strings&lt;/code&gt; heap holds the plaintext name of every type, method, field and parameter. The &lt;code&gt;#US&lt;/code&gt; (user-string) heap holds every string literal your code contains. The &lt;code&gt;#~&lt;/code&gt; stream holds the tables that stitch them together, and each method's IL is resolved from its relative virtual address. A decompiler opens the file and reads these structures. That is the whole job.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;SuppressIldasm&lt;/code&gt; flag sits &lt;em&gt;next to&lt;/em&gt; all of this, in one row of the &lt;code&gt;CustomAttribute&lt;/code&gt; table. It does not remove a single name, encrypt a single literal, or obscure a single opcode. It asks one reader to look away — and the data it would look away from is still sitting there in full for everyone else. That is why the protection was never meaningful, independent of the .NET 6 change: the thing worth protecting was never touched.&lt;/p&gt;
&lt;h2&gt;
  
  
  What actually raises the cost
&lt;/h2&gt;

&lt;p&gt;Real protection does not ask a reader to be polite. It removes or scrambles the information the reader depends on, so that a decompiler which ignores every flag still hands its operator very little.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rename the metadata.&lt;/strong&gt; The &lt;code&gt;#Strings&lt;/code&gt; heap is where meaning leaks. &lt;code&gt;CalculateMonthlyAccrual&lt;/code&gt; and &lt;code&gt;_remainingTrialDays&lt;/code&gt; tell an attacker exactly where to look. Rename them to unprintable or colliding identifiers and the decompiled output becomes a maze of &lt;code&gt;a.b(c)&lt;/code&gt; with no semantic anchors — the names are simply gone from the heap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encrypt the literals.&lt;/strong&gt; The &lt;code&gt;#US&lt;/code&gt; heap is the other giveaway: connection string shapes, API routes, error messages and license-check text all read in clear. Replace each literal with an encrypted blob and a lazy decryptor, and the heap carries ciphertext instead of your business logic in prose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reshape the flow.&lt;/strong&gt; Control-flow flattening and opaque predicates attack the &lt;em&gt;shape&lt;/em&gt; of the logic that survives in the method bodies, so even reconstructed code resists reading.&lt;/p&gt;

&lt;p&gt;In Nebula these are config, not attributes. A minimal &lt;code&gt;nebula.config.json&lt;/code&gt; that does the work &lt;code&gt;SuppressIldasm&lt;/code&gt; only pretends to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"renaming"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"mode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"dictionary"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"encryptStrings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"controlFlow"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"opaquePredicates"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"antiIldasm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then protect the built assembly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nebula protect ./bin/Release/net8.0/Billing.dll \
  --config nebula.config.json \
  --out ./protected/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note &lt;code&gt;antiIldasm&lt;/code&gt; is in that list — Nebula &lt;em&gt;will&lt;/em&gt; emit the flag if you ask, because it costs nothing and closes one trivial door on the frameworks where it still has any effect. But it is the last and least line in the file, deliberately. The three lines above it are what change the outcome. Enabling only &lt;code&gt;antiIldasm&lt;/code&gt; and shipping is the mistake this whole post exists to prevent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prove it to yourself
&lt;/h2&gt;

&lt;p&gt;You do not have to take this on faith. Build an assembly with nothing but the attribute, then open it in any modern decompiler — including a free one like Glass.NET:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Build with only [assembly: SuppressIldasm] — no other protection&lt;/span&gt;
dotnet build -c Release

&lt;span class="c"&gt;# Open the output and read the source straight back&lt;/span&gt;
glass decompile ./bin/Release/net8.0/Billing.dll --out ./recovered/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every method name, every string, every line of logic comes back. Now run the same assembly through &lt;code&gt;nebula protect&lt;/code&gt; with the config above and decompile &lt;em&gt;that&lt;/em&gt;. The names are gone, the strings are ciphertext, and the control flow fights you. That contrast is the entire argument: one approach asks a tool not to look; the other removes what the tool was looking for.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;SuppressIldasmAttribute&lt;/code&gt; is a historical courtesy between two Microsoft tools, and that courtesy ended in .NET 6. It never protected your code — it asked a single legacy disassembler to decline to show it, while leaving every name, literal and opcode fully intact for every other reader. Ship it if you like; it is free and harmless. Just never mistake it for a defence. The assembly is protected when the information an attacker needs is &lt;strong&gt;not in the file to read&lt;/strong&gt; — and that is a renaming, string-encryption and control-flow problem, not a one-line attribute.&lt;/p&gt;

&lt;p&gt;Renaming and string encryption are &lt;strong&gt;Pro&lt;/strong&gt; features in Nebula; aggressive control-flow protection is &lt;strong&gt;Enterprise&lt;/strong&gt;. The attribute is in every tier, because a checkbox that costs nothing is worth exactly what it costs.&lt;/p&gt;

</description>
      <category>obfuscation</category>
      <category>nebula</category>
    </item>
  </channel>
</rss>
