title: InvalidOperationException: Can't use schemaId .. The same schemaId is already used for type
body: <p>I receive the following error.</p>
  <pre><code>InvalidOperationException: Can't use schemaId &quot;$Registration&quot; for type &quot;$PortalService.Models.Registration&quot;. The same schemaId is already used for type &quot;$PortalService.Models.Registration&quot;
  </code></pre>
  <p>I have tried the suggestions in the following link without any succcess.</p>
  <p><a href="https://stackoverflow.com/questions/46071513/swagger-error-conflicting-schemaids-duplicate-schemaids-detected-for-types-a-a">swagger error: Conflicting schemaIds: Duplicate schemaIds detected for types A and B</a></p>
  <p>I only have one Registration class in models.  I have tried renaming the class without success.</p>
  <p>I am using an OData .Net Core 3.1 project.</p>
  <p>Configure Swagger is below</p>
  <pre><code> services.AddTransient&lt;IConfigureOptions&lt;SwaggerGenOptions&gt;, ConfigureSwaggerOptions&gt;();
              services.AddSwaggerGen(c =&gt;
              {
                  c.AddSecurityDefinition(&quot;Bearer&quot;, new OpenApiSecurityScheme
                  {
                      Description = @&quot;JWT Authorization header using the Bearer scheme. \r\n\r\n 
                        Enter 'Bearer' [space] and then your token in the text input below.
                        \r\n\r\nExample: 'Bearer 12345abcdef'&quot;,
                      Name = &quot;Authorization&quot;,
                      In = ParameterLocation.Header,
                      Type = SecuritySchemeType.ApiKey,
                      Scheme = &quot;Bearer&quot;
                  });
  
                  c.AddSecurityRequirement(new OpenApiSecurityRequirement()
                    {
                      {
                        new OpenApiSecurityScheme
                        {
                          Reference = new OpenApiReference
                            {
                              Type = ReferenceType.SecurityScheme,
                              Id = &quot;Bearer&quot;
                            },
                            Scheme = &quot;oauth2&quot;,
                            Name = &quot;Bearer&quot;,
                            In = ParameterLocation.Header,
  
                          },
                          new List&lt;string&gt;()
                        }
                      });
              });
  </code></pre>
  <p>Use Swagger is below</p>
  <pre><code>  app.UseSwagger(c =&gt;
              {
                  //c.PreSerializeFilters.Add((swaggerDoc, httpReq) =&gt; swaggerDoc.BasePath = basepath);
  
                   
                  c.PreSerializeFilters.Add((swaggerDoc, httpReq) =&gt; {
                      Microsoft.OpenApi.Models.OpenApiPaths paths = new Microsoft.OpenApi.Models.OpenApiPaths();
                      foreach (var path in swaggerDoc.Paths)
                      {
                          paths.Add(path.Key.Replace(path.Key, basepath + path.Key), path.Value);
                      }
                      swaggerDoc.Paths = paths;
                  });
              });
              app.UseSwaggerUI(
                  options =&gt;
                  {
                      options.RoutePrefix = string.Empty;
  
                      // build a swagger endpoint for each discovered API version
  
                      foreach (var description in provider.ApiVersionDescriptions)
                      {
                          options.SwaggerEndpoint($&quot;{basepath}/swagger/{description.GroupName}/swagger.json&quot;, description.GroupName.ToUpperInvariant());
                      }
  
                  });
  </code></pre>
  <p>This appears to be related to</p>
  <p><a href="https://stackoverflow.com/questions/53705270/swagger-crashes-with-circular-model-references?rq=1">Swagger crashes with circular model references</a></p>
  <p>I have found that if I comment out the partner back reference from registration, the error goes away but I need this reference.  I am not clear how to fix the situation.</p>
  <pre><code>[ForeignKey(&quot;Partner&quot;)]
  [DataMember(Name = &quot;PartnerOID&quot;)]
  [Column(TypeName = &quot;VARCHAR(100)&quot;)]
  public string PartnerOID { get; set; }
  //public virtual Partner Partner { get; set; }
  </code></pre>