Question

In our application, we have an extension for Enum

namespace System
{
    /// <summary>
    /// Contains extention methods for emuns.
    /// </summary>
    public static class EnumExtention
    {
        /// <summary>
        /// Check is value has flag.
        /// </summary>
        /// <param name="value">Checked value</param>
        /// <param name="checkedFlag">Checked flag.</param>
        /// <returns>True if enum contains specified flag. Otherwise false</returns>
        public static bool HasFlag(this Enum value, Enum checkedFlag)
        {
            ulong num = Convert.ToUInt64(checkedFlag);
            ulong num2 = Convert.ToUInt64(value);
            return (num2 & num) == num;
        }
    }
}

And somewhere in the project we have some Enum and some Func

[Flags]
public enum MyEnum
{
   zero= 0,
   two = 2,
   three = 3,
   threetwo = two | three 
}

public void SomeFunc()
{
   var ThreeTwo = Myenum.threetwo;

   bool _true = ThreeTwo.HasFlag(Myenum.three);
   bool _false = ThreeTwo.HasFlag(Myenum.zero);
   System.Windows.MessageBox.Show(String.Format("_true is: {0} and _false is : {1}", _true, _false);
 }

public void СallerFunction()
{
   try
   {
      SomeFunc();
   }
   catch (Exception ex)
   {
      System.Windows.MessageBox.Show(String.Format("Oops! {0}"), ex.Message));
   }
}

After build in release mode all wocks fine and we get this:

"_true is: true and _false is : false"

But aftet Dotfuscator worked on the code, we obtain the following:

"Oops! MethodNotFoundException"

And all Features set to Yes

Version of Dotfuscator: PreEmptive ver4.9.7000 WindowsPhoneEdition

What is wrong with the extension?

P.S. sorry for my english.

Was it helpful?

Solution

Disclaimer: My experience is with the desktop version of dotfuscator, not the phone version.

Dotfuscator may be deciding to replace the enum definitions with the equivalent constant values everywhere the enum is referenced, thereby eliminating the need for the enum type.

Try using the Dotfuscator settings to exempt the enum from obfuscation, or using the following attributes on the enum:

[Obfuscation(Exclude=true, ApplyToMembers=true, StripAfterObfuscation=true, Feature="renaming"]
[Obfuscation(Exclude=false, ApplyToMembers=true, StripAfterObfuscation=true, Feature="conditionalinclude")]

...and then if that works try allowing renaming but not removal by using just the second attribute.

After obfuscation check with ILDASM to see if the enum type is still present and that dotfuscator doing what is expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top