Workaround for Dotfuscator Error Reflection?

Greetings to all

I call Type.GetProperties (), but after running Dotfuscator it returns null elements when it returned more than zero earlier.

public class Test { public int Number { get; set; } public void ShowInfo() { Type type = this.GetType(); PropertyInfo[] props = type.GetProperties(); Console.WriteLine("type [" + type.Name + "] props count: " + props.Length); } } 

If I excluded the "Number" property from the renaming in Dotfuscator, then it works, but otherwise it doesn’t. However, for me this is not possible for all properties in my project, as this will lead to possible errors.

Are there any workarounds for this method? Or even other “free” obfuscation apps that I could use?

I already tried looking at my site to post an error, but I only use the community edition, so there seems to be not much support.

+4
source share
2 answers

Dotfuscator automatically breaks up properties (which are only metadata anyway - the real work is done using the get / set pair, which are automatically created) when renamed. It also renames the base get / set methods. Depending on what you are trying to do, you will need to exclude either the property metadata or the get / set methods (or possibly both) from the rename.

If you need to maintain the integrity of property metadata (for example, simply enumerate properties in a type), you can instruct Dotfuscator to exclude properties from renaming by checking them in the tree view on the Rename exceptions tab or using a custom regular expression rule. This will exclude property metadata - the get / set methods will still be renamed.

If you need to save the get / set methods (because, for example, you are trying to get or set the value of a property by reflection), you can instruct Dotfuscator to exclude these methods from renaming by expanding the property in the tree to view and check the get / set methods under it or using the custom rule of the regex method.

+5
source

Since the obfuscation process is not limited to renaming your class members, you cannot be sure of that. This is a confusing problem: you can no longer make any assumptions about your class regarding the result of reflection. The only way I can think is not to use reflection, but expression.

Take a look at this question and its answer to know what I mean by “expressions”: How to raise a PropertyChanged event without using a string name

+2
source

All Articles