The .NET InternalsVisibleToAttribute allows one assembly to expose its internal types and members to another assembly. Dotfuscator recognizes these relationships and adjusts Renaming and Removal behavior to preserve communication between assemblies.
Assemblies Protected Together
Assume A and B are two assemblies where assembly B references A, and A is marked with InternalsVisibleTo ( B ) .
When both friend assemblies are included in the same Dotfuscator configuration, references between them are updated automatically during protection:
- A and B are both input assemblies in library mode. If A has no other external, non-input assembly friends, Dotfuscator safely mangles internal names and fixes up the references in assembly B. If A does have other external friends, then internal names are preserved.
- A and B are both input assemblies not in library mode. Internal names in A are, by default, mangled and references in B are fixed up, regardless of the existence of other external friend assemblies. As usual in Dotfuscator, names and groups of names can be preserved via manual configuration.
External Friend Assemblies
If a friend assembly is not included in the current configuration, Dotfuscator cannot update its references.
In the scenario where A and B are two assemblies where assembly B references A, and A is marked with InternalsVisibleTo ( B ):
- A is an input assembly in library mode, and B is not an input assembly at all. Internal names in A are not mangled in order to not break potential references in B.
- A is an input assembly not in library mode, and B is not an input assembly at all. Internal names are mangled, potential references in B are not fixed up since it is not an input assembly. As usual in Dotfuscator, names and groups of names can be preserved via manual configuration. This case requires manual configuration if B actually does reference A's internals.
Best Practices
- Protect friend assemblies together whenever possible.
- Enable Library Mode for assemblies consumed by external applications.
- Test interactions between friend assemblies after protection.
Related Articles