title: A possible object cycle was detected which is not supported
body: <p>I know there are question and answers with that particular problem here on so, but my problem is little unique (I guess).</p>
  
  <p>Here is my model class:</p>
  
  <pre><code>public class RoleMaster
  {
      [Key]
      [Required]
      public int Id { get; set; }
  
      [Required]
      [StringLength(20)]        
      public string Role { get; set; }
  }
  </code></pre>
  
  <p>Here is my controller:</p>
  
  <pre><code>public class RolesController : ControllerBase
  {
      private readonly IRolesRepository _repo;
  
  
      public RolesController(IRolesRepository repo)
      {
          _repo = repo;
      }
  
  
      [HttpGet]
      public IActionResult Get()
      {
          var roles = _repo.GetRoles();
          return new JsonResult(roles);
      }
  }
  </code></pre>
  
  <p>My repository:</p>
  
  <pre><code>public interface IRolesRepository
  {
      Task&lt;IEnumerable&lt;RoleMaster&gt;&gt; GetRoles();
  }
  </code></pre>
  
  <p>and here is the GetRoles method: </p>
  
  <pre><code>public async Task&lt;IEnumerable&lt;RoleMaster&gt;&gt; GetRoles()
      {
          try
          {
              var roles = await db.RoleMaster.AsNoTracking().ToListAsync();
  
              return roles;
          }
          catch (Exception)
          {
              throw;
          }
      }
  </code></pre>
  
  <p>and this is the error I am getting: </p>
  
  <blockquote>
    <p>An unhandled exception occurred while processing the request.
        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.
        System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerCycleDetected(int maxDepth)</p>
  </blockquote>
  
  <p>From other questions I found out that if you have references with other tables then this kind of error can occur but in my case there is no other table involved. This is the first table I have created and was just trying the get method.</p>