Bugs of field order in Reflector

class Demo
{
public static int bbb = 5;
public static int aaa = bbb + 2;
}

aaa=7,bbb=5

decompiled by Reflector:

internal class Demo
{
// Fields
public static int aaa = (bbb + 2);
public static int bbb = 5;
}

aaa=2,bbb=5


Tagged:

Comments

  • nobody?
  • Can you share the IL at all?
    Have you visited our Help Centre?
  • There is no relation with IL!

    When I write this in Visual Studio:
    class Demo
    {
    public static int bbb = 5;
    public static int aaa = bbb + 2;
    }

    Then put the output to Reflector. it will like this:
    internal class Demo
    {
    // Fields
    public static int aaa = (bbb + 2);
    public static int bbb = 5;
    }


    So, when I Export Assembly Source Code, there are mistakes!

    Reflector should keep the order, or else there are different values!!!
  • CreateAndInjectCreateAndInject Posts: 5 New member
    edited July 13, 2017 1:33PM
    yzlkvwp6701n.jpg
    in my program: aaa=7,bbb=5




    5vfa180i9zjh.jpg
    but in Reflector code: aaa=2,bbb=5

  • @CreateAndInject The IL is in the static constructor (.cctor method). That is where the static variables are initialised.
  • @switchblade Why don't you test my code?

    "The IL is in the static constructor (.cctor method). That is where the static variables are initialised."

    So?

    In my original application, IL will like:
    ldc.i4.5
    stsfld bbb
    ldsfld bbb ===>this time bbb=5
    ldc.i4.2
    add
    stsfld aaa



    But Reflector change the filed order, so if I compile the decompiled source , IL will like:

    ldsfld bbb ==> this time bbb=0
    ldc.i4.2
    add
    stsfld aaa
    ldc.i4.5
    stsfld bbb


    Can't you find the difference?

    So, there is a bug!!!
  • LePatayLePatay Posts: 1 New member
    @CreateAndInject I just encountered the same problem when using server-side DataTables plugin in a ASP.NET Web Forms Site, along with Zack Owen's DataTable parser. I extracted the source code with JustDecompile and .NET Reflector, and that gave me reordered data (though the column titles were right).

    For instance, I had these columns:
        Id   |    Name    |  Birth date
    1234 | John Doe | 31/12/1990

    that were displayed like so:
             Id          |  Name  |  Birth date
    31/12/1990 |   1234   | John Doe

    This is because Reflector transformed this code:
              public class DTNomenclature
              {
                        public int PersonID { get; set; }
    
                        public string PersonName { get; set; }
    
                        public DateTime PersonBirth { get; set; }
              }
    
    into this one:
              public class DTNomenclature
              {
                        public DateTime PersonBirth { get; set; }
    
                        public int PersonID { get; set; }
    
                        public string PersonName { get; set; }
              }
    
    ... causing the DataTables parser to get the and display the data in the wrong order.

    The problem occurs here (for those who would came across this post):
              public FormatedList Parse()
              {
                        var list = new FormatedList();
                        list.Import(_properties.Select(x => x.Name).ToArray());
              ...
    
  • We're investigating this and will keep you posted.
    Have you visited our Help Centre?
Sign In or Register to comment.