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