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