Published 31 December 2012
If your application fails after pruning, this is probably because a member that was pruned is called by reflection (or any technology based on reflection, for example serialization, remoting or data-binding).
SmartAssembly usually detects that a member cannot be pruned. However, in some cases, you need to exclude the member from pruning manually.
The member that you need to exclude is the member called by reflection, not the calling member itself.
To determine which member to exclude from the pruning, you can:
- process your application without obfuscation. In case of error, use the non-obfuscated stack-trace to help you locate where the pruned member is called.
- use ASCII name mangling (instead of Unicode) for the obfuscation. This allows you to decode the stack-trace and retrieve the method where the member is called (this procedure is explained in Troubleshooting after building).
- use the error reporting feature.
Excluding members from pruning
Members excluded from pruning will be included in the resulting assembly.
To exclude members from pruning:
- On the project settings page, under Pruning, click Exclusions
- Navigate to the assembly members that you want to exclude from pruning.
- Use the checkboxes to exclude the members, then click Exclude selected:
If SmartAssembly has determined that the whole member can be pruned, instead choose whether to exclude only the definition or the whole member from pruning, then click Exclude from pruning:
- Click Apply
If you are using Linq, you must exclude any classes using the System.Data.Linq.Mapping.Table attribute from obfuscation and pruning (this also applies if they are used as a dependency). Depending on the specific application you many need to exclude other classes.
Excluding public members from pruning
By default, SmartAssembly prunes all members of executable files, including public members.
To override this behavior, manually edit the SmartAssembly project file (*.saproj) in an XML editor as follows.
- Locate the
<Assembly>element for the assembly to which you want to apply the setting.
- Add the
"1"attribute to the
<Merging>element, as in the example below.
<Assembly AssemblyName="..."> <Merging KeepPublicMembersAccessible="1"> <!-- Settings for the assembly --> </Merging> </Assembly>
This enables you to treat executable files in a similar way to DLL files.
Note that the
ExcludePublicMembers attribute on the
<Pruning> element was replaced by
KeepPublicMembersAccessible in SmartAssembly 6.7. Because the new attribute is set on the
<Merging> element, the assembly's public members are neither pruned nor obfuscated.
You can also use the
[DoNotPruneType] attributes in your source code. For more information, see Using custom attributes.
SmartAssembly does not prune public members of DLL files, because the DLL will be unusable.