12.4. About InternalsVisibleToAttribute
.NET defines System.Runtime.CompilerServices.InternalsVisibleToAttribute
class which allows to specify that types that are ordinarily visible only within the input assembly are visible to another assembly.
Although this can be useful in some scenarios, it's strongly not recommended to use that feature of .NET in Release builds because it makes the obfuscation theoretically and practically useless.
Eazfuscator.NET gives a warning message when InternalsVisibleToAttribute attribute is defined in input assembly and shuts down all obfuscation features except string encryption to save assembly functionality.
So, how to resolve this? This is not hard, really. The possible solutions are described at the sections below.
12.4.1. Solution #1. Do not use InternalsVisibleToAttribute at all
The recommended way is not to use InternalsVisibleToAttribute
at all in Release builds. At the same time it may be profitable to use the attribute in Debug builds: for example, unit test projects rely on InternalsVisibleToAttribute
to test the internal parts of the assemblies. This can be achieved by using the following code pattern, effectively applying the attribute in Debug configuration only:
#if DEBUG
[assembly: InternalsVisibleTo(<attribute parameters according to your existing code>)]
#endif
12.4.2. Solution #2. Swap with EditorBrowsable attribute
A less known but decent alternative is to use System.ComponentModel.EditorBrowsableAttribute
to mark the classes and members that you want to hide from end-users. Detailed information and sample code are available in corresponding MSDN article .
12.4.3. Solution #3. Hide the warning
It may be desirable to just hide the warning without affecting the behavior of Eazfuscator.NET.
Instructions on hiding the warning about InternalsVisibleToAttribute
-
Open obfuscatable project inside the IDE
-
Add new source file to the project and call it
ObfuscationSettings.cs
(for C#) orObfuscationSettings.vb
(for Visual Basic .NET). You may prefer to use another name instead ofObfuscationSettings.cs
orObfuscationSettings.vb
-
Fill
ObfuscationSettings.cs
with the following content (C#):using System;
using System.Reflection;
[assembly: Obfuscation(Feature = "disable warning EF-4001")]For Visual Basic .NET, fill
ObfuscationSettings.vb
with the following content:Imports System
Imports System.Reflection
<Assembly: Obfuscation(Feature:="disable warning EF-4001")>
If you think that previous solutions are not feasible then you can make Eazfuscator.NET to completely ignore InternalsVisibleToAttribute
by following the instructions below.
Instructions on making Eazfuscator.NET to ignore InternalsVisibleToAttribute
-
Open obfuscatable project inside the IDE
-
Add new source file to the project and call it
ObfuscationSettings.cs
(for C#) orObfuscationSettings.vb
(for Visual Basic .NET). You may prefer to use another name instead ofObfuscationSettings.cs
orObfuscationSettings.vb
-
Fill
ObfuscationSettings.cs
with the following content (C#):using System;
using System.Reflection;
[assembly: Obfuscation(Feature = "ignore InternalsVisibleToAttribute", Exclude = false)]For Visual Basic .NET, fill
ObfuscationSettings.vb
with the following content:Imports System
Imports System.Reflection
<Assembly: Obfuscation(Feature:="ignore InternalsVisibleToAttribute", Exclude:=False)>
Ignoring InternalsVisibleToAttribute
helps to improve obfuscation coverage but may cause some external references to internal members to fail. To restore the functionality, you should manually exclude affected members from obfuscation using conditional obfuscation.