title: .NET CORE 3 Upgrade CORS and Json(cycle) XMLHttpRequest Error
body: <p>I had my working project written in asp.net core 2.1 for a long time, but yesterday, I was forced to upgrade it to .net core 3.0 (due to 2.1 cannot call Dll' s which are written in 3.0 already).</p>
  
  <p>With that, a lot of functions were obsolete or already removed. I fixed almost all of it, but one problem with CORS. </p>
  
  <p>Like many people before me, I used:</p>
  
  <pre><code>app.UseCors(x =&gt; x
    .AllowAnyOrigin()
    .AllowAnyMethod()
    .AllowAnyHeader()
    .AllowCredentials());
  </code></pre>
  
  <p>in <code>Configure</code> function. And <code>services.AddCors()</code> in <code>ConfigureServices</code> function.</p>
  
  <p>I was able to fixed this quite easily with setting <code>WithOrigins()</code> or <code>.SetIsOriginAllowed(_ =&gt; true)</code> instead of <code>AllowAnyOrigin()</code> which does not work anymore with <code>AllowCredentials()</code>. </p>
  
  <p>After that, I was able to start the application and I thought everything is fine, but then I get stuck until now with problem I do not know, how to fix.</p>
  
  <p>I have DB relation N:N and relation table which handle that, that means I have <code>Admin</code> entity with <code>AdminProject list</code> property, then I have <code>AdminProject</code> entity with <code>Admin list</code> and <code>Project list</code> properties and <code>Project</code> entity with <code>AdminProject list</code> property once again. </p>
  
  <p>When I am listing my projects of certain admin, I am returning in Controller this <code>return Ok(projects)</code>, where I just use <code>getAll</code> on <code>AdminProject</code> entity and then with <code>Select</code> return only project. </p>
  
  <p>For that, I have to use<code>[JsonIgnore]</code> in project/admin for properties which I do not need to avoid cycling when creating json. </p>
  
  <p>With that said: <strong>NOW IN .NET CORE 3.0 AND CORS SETTINGS IT DOES NOT WORK</strong>.</p>
  
  <p>I am getting an error: 
  <code>System.Text.Json.JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32.</code> </p>
  
  <p>when debugging in console and error <code>Access to XMLHttpRequest at 'http://localhost:5000/api/project/adminlist/1' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.</code> in WEB browser</p>
  
  <p>I think I tried almost everything with Cors settings etc and I do not know why is this happening now. I also tried to JsonConvert.SerializeObject() before return it ---> <code>return Ok(JsonConvert.SerializeObject(projects))</code> and this is working, but I am not able (mentally) to do this in every single controllers functions.</p>
  
  <p>Please help! Thanks a lot!</p>