F# obfuscator

Protect compiled F# from casual reverse engineering — free, in the browser, with nothing to install.

F# decompiles too — just less prettily

It is a common assumption that F# is "naturally obfuscated" because decompiled F# looks strange. It is not. F# compiles to the same .NET assembly as C# — IL plus a metadata table holding every module, type, function and field name. Open an F# .dll in ILSpy and you get C# that is awkward to read — closures become generated classes, unions become class hierarchies — but every name you wrote is still there, and the logic follows. Awkward is not protected.

Those names are what an obfuscator rewrites. The flow is the same as for any .NET language: build the project, then upload the compiled assembly.

How to obfuscate F# code

  1. Build in Release: dotnet build -c Release.
  2. Find the output — bin/Release/net8.0/YourApp.dll. On modern .NET the .exe beside it is only a launcher; your code is in the .dll.
  3. Upload it on the home page and download the obfuscated copy.
  4. Leave FSharp.Core.dll alone — it is a reference you ship, not your code.
  5. Run the obfuscated build once before shipping.

The F#-specific things to check

Renaming only breaks code that looks something up by its original name at runtime. F# has a few idioms that do exactly that, so they are worth a specific look:

  • Serializing records and unions. JSON and other serializers match record fields and union cases by name. Public types in a library keep their names; for internal ones, add explicit serializer attributes or keep the type's names with [<Obfuscation(Exclude = true)>] (how exclusions work).
  • %A formatting. sprintf "%A" and printfn "%A" print a value's structure using reflection. After renaming, the output shows the new names. Harmless in a log line; a bug if the text is parsed or shown to users.
  • F# reflection and quotations. FSharpType, FSharpValue, [<ReflectedDefinition>] and code quotations all work from names. Type providers and some testing and mocking libraries lean on them.
  • Signature and optimization data. The F# compiler embeds extra resources so other F# projects can compile against your assembly, and those resources carry original names. A library needs them. An application that nothing compiles against does not — add --nointerfacedata --nooptimizationdata to <OtherFlags> in the project file so they are not shipped at all.

Everything else behaves as it does for C#. Obfuscation and reflection covers each failure mode, and how to test your obfuscated build is the routine that catches them before your users do.

What it protects — and what it does not

  • Names are rewritten for private and internal members always, and for the public surface of an application. A library's public API is preserved so callers still bind.
  • String literals stay readable by default. A URL or key is visible unless you enable string encryption (Pro).
  • It raises the cost of reading your code; it does not make it impossible. What obfuscation actually protects against is plain about where the line is.

Common questions

Can you obfuscate F# code?

Yes. F# compiles to a standard .NET assembly, so the same obfuscator works on it. You obfuscate the compiled .dll or .exe, not the .fs source.

Can F# code be decompiled?

Yes. ILSpy and dnSpy show an F# assembly as C#. It reads less naturally than decompiled C#, but the names and the logic are all there.

What breaks when you obfuscate F#?

Code that finds a member by name at runtime: serializing records and unions, %A formatting, F# reflection and quotations. Mark those types and test the obfuscated build once.

Any language that compiles to a managed assembly obfuscates the same way. See the .NET obfuscator overview, the C# obfuscator and the VB.NET obfuscator, or by output type: EXE obfuscator · DLL obfuscator.