title: Error "{"stateMachine":{"<>1__state":-2,"<>t__builder":{" when run project netcore
body: <p>When I run project netcore I get a message {"stateMachine":{"&lt;>1__state":-1,"&lt;>t__builder":{ and I don't know how to fix this. I see error in command line</p>
  
  <blockquote>
    <p>Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
          An unhandled exception has occurred while executing the request.
    Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'task' with type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>Microsoft.AspNetCore.Server.Kestrel[13]
          Connection id "0HLFMHMJ7MBQN", Request id "0HLFMHMJ7MBQN:00000001": An unhandled exception was thrown by the application.
    Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'task' with type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`</p>
  </blockquote>
  
  <p>This is file Startup.cs</p>
  
  <pre><code> public void ConfigureServices(IServiceCollection services)
      {
          services.AddMvc();
          services.AddDbContext&lt;AppDbContext&gt;(options =&gt;
                 options.UseSqlServer(Configuration.GetConnectionString("AppDbConnection"),
                     b =&gt; b.MigrationsAssembly("liyobe.Data")));
  
          services.AddIdentity&lt;AppUser, AppRole&gt;()
              .AddEntityFrameworkStores&lt;AppDbContext&gt;()
              .AddDefaultTokenProviders();
          // Configure Identity
          services.Configure&lt;IdentityOptions&gt;(options =&gt;
          {
              // Password settings
              options.Password.RequireDigit = true;
              options.Password.RequiredLength = 6;
              options.Password.RequireNonAlphanumeric = false;
              options.Password.RequireUppercase = false;
              options.Password.RequireLowercase = false;
  
              // Lockout settings
              options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
              options.Lockout.MaxFailedAccessAttempts = 10;
  
              // User settings
              options.User.RequireUniqueEmail = true;
          });
  
          services.AddAutoMapper();
  
          // Add application services.
          services.AddScoped&lt;UserManager&lt;AppUser&gt;, UserManager&lt;AppUser&gt;&gt;();
          services.AddScoped&lt;RoleManager&lt;AppRole&gt;, RoleManager&lt;AppRole&gt;&gt;();
  
          //CreateMapper(services, Configuration);
          //services.AddSingleton(Mapper.Configuration);
          services.AddScoped&lt;IMapper&gt;(sp =&gt; new Mapper(sp.GetRequiredService&lt;AutoMapper.IConfigurationProvider&gt;(), sp.GetService));
  
          services.AddTransient(typeof(IUnitOfWork), typeof(EFUnitOfWork));
          services.AddTransient(typeof(IAsyncRepository&lt;,&gt;), typeof(EFRepository&lt;,&gt;));
          services.AddTransient&lt;IFunctionService, FunctionService&gt;();
          services.AddTransient&lt;DbInitializer&gt;();
          //services.AddMvc();
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler("/error");
          }
          //app.UseStaticFiles();
          //app.UseHttpsRedirection();
          app.UseMvc();
      }
  </code></pre>
  
  <p>This is my file ValuesController</p>
  
  <pre><code>[Produces("application/json")]
  [Route("api/[controller]")]
  [ApiController]
  public class ValuesController : ControllerBase
  {
      IFunctionService _functionService;
      public ValuesController(IFunctionService functionService)
      {
          _functionService = functionService;
      }
      // GET api/values
      [HttpGet]
      public async  Task&lt;IActionResult&gt; Get()
      {
          try
          {
              var data = _functionService.GetAll("");
              return Ok(data);
          }
          catch (Exception ex)
          {
              throw new Exception();
          }
      }
  </code></pre>
  
  <p>This is function getAll in class FunctionService</p>
  
  <pre><code>public async Task&lt;List&lt;FunctionViewModel&gt;&gt; GetAll(string functionId)
      {
          var query = await _functionRepository.ListAllAsync();
          var result = _mapper.Map&lt;List&lt;Function&gt;, List&lt;FunctionViewModel&gt;&gt;(query);
          return result;
      }
  </code></pre>
  
  <p>This is class Function</p>
  
  <pre><code>public class FunctionViewModel
  {
      public string Id { get; set; }
  
      [Required]
      [StringLength(128)]
      public string Name { set; get; }
  
      [Required]
      [StringLength(250)]
      public string URL { set; get; }
  
      [StringLength(128)]
      public string ParentId { set; get; }
  
      public string IconCss { get; set; }
      public int SortOrder { set; get; }
      public bool Status { set; get; }
  }
  </code></pre>
  
  <p>This is class Function</p>
  
  <pre><code>[Table("Functions")]
  public class Function : BaseEntity&lt;string&gt;, ISwitchable, ISortable
  {
      public Function()
      {
  
      }
      public Function(string name, string url, string parentId, string iconCss, int sortOrder)
      {
          this.Name = name;
          this.URL = url;
          this.ParentId = parentId;
          this.IconCss = iconCss;
          this.SortOrder = sortOrder;
      }
      [Required]
      [StringLength(128)]
      public string Name { set; get; }
  
      [Required]
      [StringLength(250)]
      public string URL { set; get; }
  
  
      [StringLength(128)]
      public string ParentId { set; get; }
  
      public string IconCss { get; set; }
      public int SortOrder { set; get; }
      public bool Status { set; get; }
  }
  </code></pre>
  
  <p>I see the error occur when I return data in FunctionService. But I don't know how to fix this.</p>