Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 94857

Bug new Instance with inlined values to self (instance)

$
0
0

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




Viewing all articles
Browse latest Browse all 94857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>