Bug new Instance with inlined values to self (instance)

2 posts, 1 answers
  1. Blamara
    Blamara avatar
    10 posts
    Member since:
    Dec 2014

    Posted 04 Apr 2015 Link to this post

    Lots of API functions use structures, and a lot of structures have size member.
    So when we try to decompile following code we will end up with error.

     

    struct NewInstanceInlined
    {
      public int size;
      public int dummy;
     
      public static NewInstanceInlined Create()
      {
        int x = 11;
        NewInstanceInlined instance = new NewInstanceInlined();
        instance.size = Marshal.SizeOf(instance);
        ++x;
        instance.dummy = x;
        return instance;
      }
    }

    And we decompile with Telerik Decompiler we get:

    internal struct NewInstanceInlined
    {
        public int size;
     
        public int dummy;
     
        public static NewInstanceInlined Create()
        {
            int x = 11;
            NewInstanceInlined instance = new NewInstanceInlined()
            {
                size = Marshal.SizeOf(instance),
                dummy = x + 1
            };
            return instance;
        }
    }

    you can see that line  size = Marshal.SizeOf(instance),
    can't be compiled since "instance" object is not yet created (== unassigned, non existing, and compiler raises error CS0165).



  2. Answer
    Alexander
    Admin
    Alexander avatar
    80 posts

    Posted 07 Apr 2015 Link to this post

    Hello Blamara,

    Thank you for letting us know about this problem. I really appreciate it.

    The bug is added to our backlog and will be fixed as soon as possible.

    Please, update regularly and stay tuned.

    Regards,
    Alexander
    Telerik
  3. DevCraft banner
Back to Top