aspnetboilerplate: Navigation property 'Claims' on entity of type 'User' cannot be loaded because the entity is not being tracked.

Abp Version:3.6.2 .Net Core Version:2.1.0 Ef Core Version:2.1

When I upgrade to .net core 2.1, after the user login in, idle for a period of time (without any operation and not close browser), it will throw the following error:

InvalidOperationException: Navigation property 'Claims' on entity of type 'User' cannot be loaded because the entity is not being tracked. Navigation properties can only be loaded for tracked entities.

image

image

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 24 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Identity 2.1 made some changes. It re-registered with ISecurityStampValidator

AddSignInManagerDeps

It covers AddAbpSecurityStampValidator<UserSecurityStampValidator>()

So only need to change the registration order can be solved.

 return services.AddAbpIdentity<Tenant, User, Role>()
                .AddAbpTenantManager<TenantManager>()
                .AddAbpUserManager<UserManager>()
                .AddAbpRoleManager<RoleManager>()
                .AddAbpEditionManager<AbpEditionManager>()
                .AddAbpUserStore<UserStore>()
                .AddAbpRoleStore<RoleStore>()
                
                .AddAbpSignInManager<UserSignInManager>()

                .AddAbpUserClaimsPrincipalFactory<UserClaimsPrincipalFactory>()
                .AddAbpSecurityStampValidator<UserSecurityStampValidator>()
                .AddPermissionChecker<UserPermissionChecker>()

                //.AddAbpSignInManager<UserSignInManager>()

                .AddFeatureValueStore<AbpFeatureValueStore<Tenant, User>>()
                .AddDefaultTokenProviders();

Hi,

This is happening for us also after upgrade from 3.5.x to 3.7. We are using Kesteral hosting, so anything to do with IIS recycling can be discounted. (we are still in development only)

What i have found solves the problem is to delete all cookies and restart the browser, at this point you are asked to log in again, and all is well-- clearly not a production solution.

Will update if i learn more about how to reproduce.

my ef.core project csproj file content:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="Migrations\20180421141200_AddVendorAndSellerApplicationTable.cs" />
    <Compile Remove="Migrations\20180507150825_AddItemApproveHistories.cs" />
    <Compile Remove="Migrations\20180507153104_SyncDB.cs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\ZHT.Domains\ZHT.Domains.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="Abp.ZeroCore.EntityFrameworkCore">
      <HintPath>C:\Users\baiyunchen\.nuget\packages\abp.zerocore.entityframeworkcore\3.4.0\lib\netstandard2.0\Abp.ZeroCore.EntityFrameworkCore.dll</HintPath>
    </Reference>
  </ItemGroup>

</Project>

My Web project csproj file Content:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />
    <PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.0.0" />
    <PackageReference Include="MiniProfiler.EntityFrameworkCore" Version="4.0.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\ZHT.EfCore\ZHT.EfCore.csproj" />
    <ProjectReference Include="..\ZHT.Services\ZHT.Services.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Content Update="App_Data\Languages\ZHTShopWeb.en.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Update="App_Data\Languages\ZHTShopWeb.zh-CN.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Update="wwwroot\favicon.ico">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Models\Home\" />
    <Folder Include="Properties\" />
  </ItemGroup>

</Project>