title: Swagger crashes with circular model references
body: <p>I have a .Net Core 2.2 OData API, for which I'm tying to implement Swagger documentation.</p>
  
  <p>I've been following this example: <a href="https://github.com/Microsoft/aspnet-api-versioning/tree/master/samples/aspnetcore/SwaggerODataSample" rel="nofollow noreferrer">https://github.com/Microsoft/aspnet-api-versioning/tree/master/samples/aspnetcore/SwaggerODataSample</a></p>
  
  <p>I've got it working up to a point.
  Now I'm facing an issue with my models referencing each other in a circular manner, let me explain:</p>
  
  <p><em>Note: I used EFCore Code first approach for handling my DB.</em></p>
  
  <p>I have these models (as an example): Project, ProjectLocation, ProjectRegion.
  Lets call them A, B &amp; C to keep things short.</p>
  
  <p>A has references to B &amp; C like so:</p>
  
  <pre><code>public virtual ICollection&lt;X&gt; X{ get; set; }
  </code></pre>
  
  <p>And both B &amp; C reference A directly like so:</p>
  
  <pre><code>public A A{ get; set; }
  </code></pre>
  
  <p>This is all pretty standard relational DB model stuff, but it seems SwaggerUI can't handle this.</p>
  
  <p>The error I'm getting is as follows:</p>
  
  <blockquote>
    <p>Failed to load API definition.
    Errors:
    Fetch error:
    Internal Server Error /swagger/v1/swagger.json</p>
    
    <p>An unhandled exception occurred while processing the request.
    TypeLoadException: Could not load type 'NCCRD.Services.DataV2.Database.Models.ProjectLocation' from assembly 'Tc2fc56a7babe40419a678a075439246c.DynamicModels, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.</p>
  </blockquote>
  
  <p>System.Signature.GetSignature(Void* pCorSig, int cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)</p>
  
  <p><em>A stack-trace is also available if needed.</em></p>
  
  <p>I've read these two posts and all of the references links as far as I could go, but did not find a solution that works:</p>
  
  <p><a href="https://github.com/swagger-api/swagger-codegen/issues/741" rel="nofollow noreferrer">https://github.com/swagger-api/swagger-codegen/issues/741</a></p>
  
  <p><a href="https://github.com/swagger-api/swagger-codegen/issues/728" rel="nofollow noreferrer">https://github.com/swagger-api/swagger-codegen/issues/728</a></p>
  
  <p>Once solution that seemed good was this: <a href="https://systemout.net/2017/04/07/swagger-asp-net-core-fixing-circular-self-references/" rel="nofollow noreferrer">https://systemout.net/2017/04/07/swagger-asp-net-core-fixing-circular-self-references/</a>, but this too had no effect. (I contacted to author for help too)</p>
  
  <p>The moment I remove the reference to A from either B or C, then SwaggerUI loads up fine.</p>
  
  <p>If anyone could shed some light on this I'd really appreciate it.
  Thanks in advance to any help offered.</p>