Protecting a .NET desktop application (WPF and WinForms)

A desktop app is the clearest case for obfuscation: you ship the assembly to a PC anyone can decompile. The desktop-specific workflow — which file to protect, what breaks in WPF and WinForms binding, how to layer it, and signing and testing.

A desktop application is the clearest case for obfuscation there is: you ship the compiled assembly to a customer's PC, where anyone can open it in a decompiler and read your code back as near-original C#. Because it is code you distribute, protecting it is worth doing — see do you need to obfuscate server-side code? for why the "shipped vs hosted" line is what matters. This guide is the desktop-specific workflow: which file to protect, what breaks in WPF and WinForms, how to configure the layers, and how to verify before you ship.

Check this first: which file is your code in? On .NET Framework, YourApp.exe is the managed assembly — obfuscate that. On .NET 5, 6, 7, 8+ the YourApp.exe beside your build is a native launcher with no managed code; your actual C# is the same-named YourApp.dll. Upload the .dll. Protecting the launcher does nothing. Why public names are only renamed in applications explains the file question in full.

The desktop-specific hazard: UI binding by name

Renaming is safe except where something resolves a member by its string name at runtime — and desktop UI frameworks do exactly that, which makes them the place to be careful.

  • WPF / XAML. A {Binding CustomerName} looks up a property called CustomerName. Rename it and the binding silently resolves to nothing — you get a window with empty fields and no exception, which is far easier to miss than a crash. Anything referenced from XAML needs to keep its name: bound properties, ICommand commands, value converters, and code-behind event handlers wired up in markup.
  • WinForms. The designer serializes the form into .Designer.cs and data binds controls to property names. Data-bound properties and anything the designer references by name need to survive renaming.

This is the same root cause as every other obfuscation break, handled once and properly in obfuscation and reflection: what breaks and why — pin the names that cross a boundary (bindings, serialized settings, config) with attributes or exclusions, and renaming becomes harmless. The desktop twist is only that WPF's failure is quiet, so you must look at every view, not just wait for an exception.

Also watch: settings, config and plugins

  • User settings (Properties.Settings) and app.config sections map to type and property names; pin the ones that persist across versions so an upgraded build still reads an existing user's settings.
  • Plugin or add-in loading by type name — anything doing Type.GetType("MyApp.Exporters.CsvExporter") breaks. Keep the shared contract assembly unobfuscated; protect the implementation, which is where the value is.

A configuration that fits a commercial desktop app

A paid desktop app sold to the public is the textbook "anyone can buy a copy and decompile it at leisure" case. A sensible layering:

  • Renaming + block ILDasm — always; the free-tier floor.
  • String encryption — if your binary carries endpoint URLs, feature flags, telling messages or anything you would rather not hand over in a strings dump.
  • Control-flow obfuscation and reference proxying — across the assembly, so the logic and the map of what you call do not decompile cleanly.
  • Method virtualization — reserved for the one or two methods that are the product (a licence or activation routine, a proprietary calculation), and only if they are not on a hot path.

The layer decision guide walks the reasoning behind this and tells you where to stop; the Pro layers (everything past renaming) are on the $29/month plan.

Licensing is the usual motive — so be clear-eyed about it. A licence check that runs on the customer's machine can ultimately be defeated, because the machine is theirs. Obfuscation (and virtualizing the check) raises the cost of patching it a great deal, but what actually changes the outcome is server-side validation. And encrypting a licence key with string encryption does not make the binary a safe vault for a master secret — the decryptor ships with it. Protect the client to raise the bar; put anything that must not be forged on a server.

Sign after obfuscating, not before

Obfuscation rewrites the assembly, which invalidates any signature already on it. So the order is fixed: build → obfuscate → sign, with Authenticode (and strong naming, if you use it) as the last step on the obfuscated files. Getting this backwards ships a build with a broken signature. The full sequence, including the .NET Core launcher detail, is in obfuscation and code signing. Installers follow the same rule — sign the obfuscated binaries first, then build the ClickOnce or MSIX package around them.

Verify before you ship — every view

Because WPF binding failures are silent, testing is not optional here. Run your suite against the obfuscated build, then launch it and walk every window: confirm fields populate (empty ones mean a renamed bound property), commands fire, converters run, settings load, and the licence path still validates. The repeatable workflow — and how to gate it in CI — is in how to test your obfuscated build before you ship. Keep the unobfuscated build and the Pro rename map for every release so a field crash's obfuscated stack trace can be read back to your names.

In short

Obfuscate the right file (the .dll on modern .NET), keep UI-bound and persisted names pinned, layer renaming → string encryption → control-flow for a commercial build and reserve virtualization for the crown-jewel method, sign last, and test every view on the protected build. Do that and a desktop app — the most exposed thing you can ship — stops handing its source to anyone with a decompiler.

Deciding whether this fits your product? The commercial desktop applications use case lays out the risks, the limits and a test checklist. Building for phones as well? See the .NET MAUI and Xamarin obfuscator page.

Try it on your own assembly

Upload a DLL or EXE and download the obfuscated result. Free, no signup, nothing stored.