A Unified Theory of Multi-Assembly .NET Obfuscation: It's a Rename Refactoring, and the Compiler Already Went Home published
Your build is green. Your tests pass. You ship. A customer opens the app and gets System.MissingMethodException - pointing at a method that has existed, untouched, since 2019. If that sentence gave you flashbacks, this
Your build is green. Your tests pass. You ship. A customer opens the app and gets System.MissingMethodException - pointing at a method that has existed, untouched, since 2019.
If that sentence gave you flashbacks, this post is for you. And if you're about to obfuscate a multi-project .NET solution for the first time, read this first, because that exception is already circling.
Here's my claim: multi-assembly obfuscation is not five separate problems (public APIs, DTOs, reflection, build order, packaging). It's one problem wearing five costumes. Once you see the mechanism underneath, all the usual folklore - "obfuscate in dependency order," "freeze your contracts," "exclude serialized DTOs" - stops being rules you memorize and becomes stuff you could have derived yourself.
So let's derive it.
The toy solution
Everything below uses this layout, which is roughly the shape of every commercial .NET desktop app I've ever seen:
MyApp.sln
βββ MyApp.Data β queries, persistence
βββ MyApp.Core β domain logic, shared helpers, DTOs
βββ MyApp.Licensing β activation and key checks (the crown jewels)
βββ MyApp.UI β WPF views + resource dictionaries
βββ MyApp β the exe, composition root
The mental model
When you rename a method in your IDE, thousands of references update and the compiler verifies that nothing was missed. That verification is the safety net that makes rename refactoring boring.
An obfuscator does the same kind of renaming - but it runs on the compiled output, after the compiler has clocked out. Nobody re-checks the references. You've inherited the compiler's job.
To do that job, you need to know where names actually live in a .NET solution. There are exactly three places:
1. Assembly metadata. The reference tables the compiler emits - MyApp.UI's IL literally contains "call MyApp.Core.LicenseService::ValidateKey," resolved by name when the assemblies load. These are recorded references, and a good obfuscator can rewrite both ends consistently.
2. String literals in your code. GetMethod("ValidateKey"), serializers that map properties by name, DI registrations, XAML bindings. To the compiler these are just data. It never checks them against real names - which is why your IDE also never flags them during a normal rename.
3. Names consumed outside your solution. Plugins, external tools, other processes. Boundaries you don't compile.
And the unified theory in one sentence:
An obfuscator can repair category 1 if every assembly on both ends participates, it cannot see category 2 unless you tell it, and it must never touch category 3.
Every multi-assembly failure you'll ever debug is a name that was sitting in the wrong category. Your "internal" public method that a plugin also calls? Category 3 masquerading as category 1. The DTO that was in-memory-only until someone serialized it last sprint? Category 2 wearing a category 1 costume.
Proof by experiment
Don't take my word for it. Take this pair of calls:
// MyApp.Core/LicenseService.cs
public class LicenseService
{
public bool ValidateKey(string key) => key.Length == 29; // sure, why not
}
// MyApp.UI - two ways to reach the same method
var viaMetadata = license.ValidateKey(key); // category 1
var viaString = (bool)typeof(LicenseService)
.GetMethod("ValidateKey")!
.Invoke(license, new object[] { key }); // category 2
Now obfuscate different combinations of assemblies and watch what survives:
| Assemblies obfuscated |
ValidateKey renamed? |
viaMetadata |
viaString |
|---|---|---|---|
| none | - | β works (but decompiles clean) | β works |
| Core only | yes | β MissingMethodException
|
β GetMethod returns null |
| Core + UI together | yes | β (references repaired) | β still null |
| Core + UI together | excluded | β | β |
That table is the entire topic. The rest of this post is footnotes.
The five rules the model hands you
Rule 1 - Everyone's in the set, or consciously out
Category-1 references only survive if both ends participate. That means every first-party assembly you ship goes through the tool - the exe alone protects nothing, because the crown jewels live in Licensing.dll, not Program.cs. Two deliberate exceptions: third-party NuGet packages and framework DLLs stay out (you don't own them), and pure contract assemblies join selectively - public surface frozen, private implementation still protected.
Rule 2 - A name is a contract the moment it leaves the set
C# forces you to mark members public merely so another assembly can see them. That's not an API - that's plumbing with a wider doorway. If the only consumers are your own obfuscated assemblies, rename freely. The moment a name crosses to a plugin, another process, or an external tool, freeze it.
One sneaky variant: InternalsVisibleTo means your internal members are a contract too. Friend assemblies count as "outside" for the purposes of renaming internals.
Rule 3 - Treat string references as public API
Before enabling renaming, audit the strings that are really names:
GetMethod GetProperty GetField GetType CreateInstance
Same for serialized DTOs. The moment LicenseRequest travels through JSON, XML, or MessagePack, its property names are the wire format, and renaming them corrupts the payload silently. For each hit you have two options: exclude it, or eliminate it - replacing string-based lookups with strongly typed delegates or source generators. The second option is strictly better, because it lets the rest of the assembly stay protected.
Rule 4 - The build machine is part of the graph
If your obfuscator rewrites DLLs in place while Visual Studio builds projects in parallel, you'll meet "file in use" errors eventually - one project loading a DLL mid-rewrite. Set maximum parallel project builds to 1 (Tools β Options β Projects and Solutions β Build and Run) for any solution that obfuscates post-build, and process assemblies in dependency order: leaves first, the exe last. The order is the contract.
Two more build-graph residents: if you strong-name your assemblies, every rewritten one must be re-signed; and on WPF, any assembly carrying BAML - resource dictionaries count! - has to go through the tool too, or you'll get XAML parse errors from renamed references. (Opaquer repairs cross-assembly BAML references, but only for assemblies it actually processes.)
Rule 5 - The release is the unit of protection
Never test, and never ship, a mix of protected and unprotected first-party DLLs. Run your whole test suite against the complete protected set. Install the actual package on a clean machine. Open your own app in ILSpy before shipping - verify your work the way an attacker will.
And watch the classic installer trap: a setup project that captured "Primary Output" before obfuscation will faithfully package the unprotected versions of everything. Obfuscate first, then point the setup at the protected files. Archive the rename maps and logs with the release; the first scrambled stack trace from a customer is a support ticket, and the map is the translation.
Making it real: Opaquer, one settings file per project
The nice thing about this model is that it tells you what your tooling must look like. Different assemblies need different aggression - Licensing gets everything, contracts get surgical exclusions - so a single global config can't work. You want one settings file per project, in source control, reviewable in PRs.
In Opaquer's GUI, open each assembly, configure renaming / string encryption / control flow / exclusions, and save the settings as OpaquerSettings.xml next to that project (or as a named profile, F4). Then a script walks them in order:
# protect.ps1 - run after a Release build (adjust $out for your TFM)
$opaquer = "C:\Program Files (x86)\Rustemsoft\Opaquer\Opaquer.exe"
$out = "bin\Release\net8.0"
# leaf projects first, entry point last - the order is the contract
$assemblyOrder = @(
'MyApp.Data.dll',
'MyApp.Core.dll',
'MyApp.Licensing.dll',
'MyApp.UI.dll',
'MyApp.exe'
)
foreach ($asm in $assemblyOrder) {
$project = [IO.Path]::GetFileNameWithoutExtension($asm)
& $opaquer `
-x="$project\OpaquerSettings.xml" `
-SOURCE="$out\$asm" `
-OUTPUT="$out\$asm" `
-KEY="KeyFile.snk" `
-WRITELOG="$out\Opaquer.$project.log"
if ($LASTEXITCODE -ne 0) {
throw "Obfuscation failed for $project - check $out\Opaquer.$project.log"
}
}
If you saved named profiles instead of XML files, the loop body collapses to & $opaquer $project.
That $LASTEXITCODE check matters more than it looks: in CI, the throw is the difference between a red build and a silently unprotected release.
TL;DR - the whole post in seven lines
- Obfuscation is a rename refactoring with no compiler watching.
- Names live in three places: metadata (repairable), strings (invisible), external consumers (untouchable).
- Every shipped first-party assembly participates; third-party stays out.
- A name crossing your boundary - plugin, serializer, reflection, friend assembly - is a contract: freeze it.
- Grep for
GetMethod/GetType/CreateInstance, then exclude or eliminate. - Parallel builds = 1; leaves first, exe last; re-sign everything.
- Test the full protected set on a clean machine, and keep the logs.
If you want to poke at the tool from the examples, the repo's here:
Rustemsoft
/
Opaquer
A Robust and Professionally Engineered .NET Obfuscator
Opaquer is an advanced .NET code protection and obfuscation system designed to safeguard commercial applications from reverse engineering, tampering, and intellectual property theft.
Opaquer offers three price models: a free Basic version with core obfuscation features, a Pro version adding CLI automation, and an Enterprise edition with team licensing, offline build support, and high-intensity control flow obfuscation.
Opaquer .NET Obfuscator offers a comprehensive professional solution for protecting .NET applications, supporting both .NET Core and .NET Framework. By leveraging Opaquer, developers can effectively shield their Microsoft .NET applications from reverse engineering, unauthorized code modifications, and intellectual property theft. The obfuscation process significantly enhances application security by rendering the code unreadable and complex, as the program logic becomes highly confusing after obfuscation. The tool supports a wide range of obfuscation methods, including DLL obfuscation, executable obfuscation, advanced Control Flow obfuscation, String Encryption, Reference obfuscation, and Metadata obfuscation. It ensures that all namespacesβ¦
Documentation, including the exclusion and CLI details: opaquer.net/opaquerdoc.html
One question I'm genuinely curious about: where do you draw the plumbing-vs-contract line? My current heuristic is "would code I don't compile ever hold this name?" - but I suspect some of you have a sharper test. Comments are open.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.