Invalid Code


This protection adds invalid code to the methods so that decompilers cannot interpret them.


This protection is available in the editions:

Community Professional Enterprise


Invalid code added in the methods is not executed, for this reason it does not affect the operation or performance of the applications in a negative way

Parameters

{info} This protection has no parameters or settings.

Modes

  • Normal: Add invalid metadata to prevent the code from being decompiled.

Code example

  • Before
var key =  "https://www.dotnetsafer.com";
string password = "admin";
  • After
/*
An exception occurred when decompiling this method (06000001)

ICSharpCode.Decompiler.DecompilerException: Error decompiling System.Void Testnetcoreapp30.Program::Main(System.String[])
 ---> System.Exception: Inconsistent stack size at IL_1A
 en ICSharpCode.Decompiler.ILAst.ILAstBuilder.StackAnalysis(MethodDef methodDef) en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstBuilder.cs:line 443
 en ICSharpCode.Decompiler.ILAst.ILAstBuilder.Build(MethodDef methodDef, Boolean optimize, DecompilerContext context) en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\ILAst\ILAstBuilder.cs:line 269
 en ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(IEnumerable`1 parameters, MethodDebugInfoBuilder& builder) en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 112
 en ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDef methodDef, DecompilerContext context, AutoPropertyProvider autoPropertyProvider, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, StringBuilder sb, MethodDebugInfoBuilder& stmtsBuilder) en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 88
 --- End of internal exception stack tracking ---
 en ICSharpCode.Decompiler.Ast.AstMethodBodyBuilder.CreateMethodBody(MethodDef methodDef, DecompilerContext context, AutoPropertyProvider autoPropertyProvider, IEnumerable`1 parameters, Boolean valueParameterIsKeyword, StringBuilder sb, MethodDebugInfoBuilder& stmtsBuilder) en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstMethodBodyBuilder.cs:line 92
 en ICSharpCode.Decompiler.Ast.AstBuilder.<>c__DisplayClass89_1.<AddMethodBody>b__0() en C:\projects\dnspy\Extensions\ILSpy.Decompiler\ICSharpCode.Decompiler\ICSharpCode.Decompiler\Ast\AstBuilder.cs:line 1531
*/

Exclusions

  • Exclude with attribute

    Include this attribute in your source code:

[Obfuscation(Exclude = true, Feature = "InvalidCode")]
  • Exclude from the interface

    You can exclude this protection from the methods or classes you want.

Compatibility

Platform Compatibility
.NET Framework Full compatibility, compatible versions: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0.
ASP .NET Full compatibility, compatible versions: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0.
Windows Phone Compatibility subject to the version of the framework, compatible in general aspects.
WPF Full compatibility, available in all versions.
SQL CLR Applications Compatibility subject to the version of the framework, compatible in general aspects.
Silverlight Compatibility subject to the version of the framework, compatible in general aspects.
Xamarin.iOS Partial compatibility, compatible versions: 10.8. Xamarin is not fully adapted in dotnetsafer
Xamarin.Mac This version is under development, availability has not been checked.
Xamarin.Andoid This version is under development, availability has not been checked.
.NET Core Full compatibility, compatible versions: 3.1, 3.0, 2.2, 2.1, 2.0.
.NET Standard Library Full compatibility, compatible versions: 2.1, 2.0.
Unity Compatibility subject to the version of the framework, compatible in general aspects.
UWP Compatibility subject to the version of the framework, compatible in general aspects.
Satellite Assembly Suppor Compatibility subject to the version of the framework, compatible in general aspects.
WinRT Compatibility subject to the version of the framework, compatible in general aspects.
Integrated ClickOnce Compatibility subject to the version of the framework, compatible in general aspects.
Managed C++ (Mixed Mode) Assembly Support Compatibility subject to the version of the framework, compatible in general aspects.