Building an application with SmartAssembly can cause three main types of problem:
This page explains why these problems can occur, and how to solve them.
If you've enabled Method parent obfuscation, disable method parent obfuscation and try again. Method parent obfuscation significantly alters your assembly, and it doesn't work with all assemblies.
If your assembly has a .exe.config file, make sure that the .exe.config file is copied to the output directory.
To identify the cause of the problem, if the problem is not in a DLL:
To identify the cause of the problem, if the problem is in a DLL:
To do this, go to the Project settings, and go to Obfuscation. Select I want to obfuscate using only ASCII characters and I want to use a one-to-one renaming scheme.
When you've identified the line where the error occurs, check whether the following technologies are used at that line. If they are, see below for the appropriate solution:
In other cases, contact support for further guidance.
Obfuscation by name mangling renames methods and types. Normally, any given method or type will be renamed the same way throughout the SmartAssembly project, otherwise no application would work.
If you use reflection to call a method or type by name, the reference might not be renamed, and so the application will not work.
For example, imagine a simple calculator application, in which the Add() method is in a DLL called from the executable. After obfuscation, the Add() method is renamed to #KXf but the executable still contains the following line:
long sum = (long)addType.InvokeMember("Add", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, addInstance, new object[] { num1, num2 }); |
After you've used error reporting to identify where the problem occurs, you can solve the problem:
[DoNotObfuscate]
attribute. For more information, see Using custom attributes.Reflection works with obfuscation if you do not use names. |
The problem described above can also affect serialization. When a serialized object is unserialized, reflection is used to match the member's name in the serialized object to a name specified in the code.
If an error occurs, ensure that you have used the [Serializable]
Attribute on all serializable classes, including classes that are XML serialized. For more information, see Using custom attributes.
Avoid writing obfuscated, serialized objects to files that might be opened in different builds of your assembly.
For more information about why serialization exceptions may occur, see Serialization exceptions occurring in obfuscated assemblies.
When you use SmartAssembly to prune code, it normally only removes code that is never called from other parts of the code. However, sometimes code is useful even if it is not called from anywhere else.
An example of this is WPF, where code might be referenced from the XAML file, but not from other parts of the code. SmartAssembly might prune this code, even though it is needed.
After you have used error reporting to identify where the problem occurs, exclude that code from pruning. For more details see Pruning unused code.
Enums in merged dependencies containing WPF code might not be found. If this happens, you can either:
[DoNotObfuscate]
attribute to exclude the enum from obfuscation<
DoNotObfuscateAnyEnums/>
option in your *.saprojfile to exclude all enums in the assembly from obfuscationAfter building, if you inspect your assembly using .NET Reflector or similar, you may find that some code that you expected to be obfuscated has not been obfuscated by SmartAssembly.
This is because SmartAssembly will not obfuscate code if it determines that obfuscation might cause your application not to work, or that a string might be displayed in the user interface.
To see why SmartAssembly has not obfuscated your code, you can create a log file in 'TRACE' mode. For more information, see Log file for SmartAssembly.
The following types are always excluded from obfuscation to ensure that your application works correctly:
Serializable
attribute.System.MulticastDelegate
.System.ServiceModel.OperationContractAttribute
specified.System.ServiceModel.ServiceContractAttribute
specified.System.Xml.Serialization
.System.Reflection.DefaultMemberAttribute
specified.In addition, SmartAssembly might not obfuscate some of your types for the reasons described below:
Format
, GetName
, GetNames
, Parse
, or ToString
called on them will be displayed to users. These enums are therefore excluded from obfuscation automatically.To avoid stopping your assembly from working, SmartAssembly does not merge or embed the following dependencies:
If you want to merge or embed a Microsoft assembly that is not a Framework Class Library, a workaround is described in Troubleshooting merging problems.