title: How can I find out why AutoFixture is throwing Kernel.OmitSpecimen exception
body: <p>I am working on a fairly nested model which has some circular references. It also uses Entity Framework so all lists are <code>ICollection&lt;T&gt;</code>. To accommodate this I am configuring AutoFixture like so:</p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code>_fixture = new Fixture().Customize(new MultipleCustomization());
  _fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
  _fixture.Behaviors.Add(new OmitOnRecursionBehavior());
  </code></pre>
  
  <p>When I try to create a type </p>
  
  <pre class="lang-cs prettyprint-override"><code>_fixture.CreateAnonymous&lt;Session&gt;();
  </code></pre>
  
  <p>AutoFixture has a problem and throws the following error </p>
  
  <blockquote>
    <p>System.InvalidCastException : Unable to cast object of type 'Ploeh.AutoFixture.Kernel.OmitSpecimen' to type 'The.Model.Language'</p>
  </blockquote>
  
  <p>If I exclude the collection within <code>Session</code> of type <code>Language</code>, AutoFixture throws the same exception for another type in the graph. </p>
  
  <p>Is there a way to extract more information from AutoFixture, e.g., the property that caused the error?</p>
  
  <p>Why is AutoFixture trying to cast my type to OmitSpecimen and what in this process could have happened to prevent it from being cast?</p>
  
  <p>I've created a gist for the stack trace <a href="https://gist.github.com/3766612" rel="nofollow">here</a>.</p>
  
  <h2>Update</h2>
  
  <p>I have managed to recreate the problem. Given this pair of objects</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class Session
  {
      public Language Language { get; set; }
  }
  
  public class Language
  {
      public ICollection&lt;Session&gt; Sessions { get; set; }
  }
  </code></pre>
  
  <p>The call to <code>_fixture.CreateAnonymous&lt;Session&gt;();</code> will throw the cast exception.</p>