This is a migrated thread and some comments may be shown as answers.

Bug new Instance with inlined values to self (instance)

1 Answer 25 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Blamara
Top achievements
Rank 1
Blamara asked on 04 Apr 2015, 08:39 AM

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).



1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 07 Apr 2015, 02:58 PM
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
Tags
General Discussions
Asked by
Blamara
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or