When I launch the following tests in Release mode, they both pass, but in Debug mode they both fail.
[TestFixture]
public unsafe class WrapperTests
{
    [Test]
    public void should_correctly_set_the_size()
    {
        var wrapper = new Wrapper();
        wrapper.q->size = 1;
        Assert.AreEqual(1, wrapper.rep()->size);  // Expected 1 But was: 0
    }
    [Test]
    public void should_correctly_set_the_refcount()
    {
        var wrapper = new Wrapper();
        Assert.AreEqual(1, wrapper.rep()->refcount); // Expected 1 But was:508011008
    }
}
public unsafe class Wrapper
{
    private Rep* q;
    public Wrapper()
    {
        var rep = new Rep();
        q = &rep;
        q->refcount = 1;
    }
    public Rep* rep()
    {
        return q;
    }
}
public unsafe struct Rep
{
    public int refcount;
    public int size;
    public double* data;
}
However if I remove the rep() method and make the q pointer public, tests pass both in debug and release mode.
[TestFixture]
public unsafe class WrapperTests
{
    [Test]
    public void should_correctly_set_the_size()
    {
        var wrapper = new Wrapper();
        wrapper.q->size = 1;
        Assert.AreEqual(1, wrapper.q->size);   
    }
    [Test]
    public void should_correctly_set_the_refcount()
    {
        var wrapper = new Wrapper();
        Assert.AreEqual(1, wrapper.q->refcount);  
    }
}
public unsafe class Wrapper
{
    public Rep* q;
    public Wrapper()
    {
        var rep = new Rep();
        q = &rep;
        q->refcount = 1;
    } 
}
public unsafe struct Rep
{
    public int refcount;
    public int size;
    public double* data;
}
I don't understand what can cause this behavior?
Why does the test fail when I use a method to return the value of q ?