Open Closed

AuthServer Error, the page can't access , Swagger can access #10698


User avatar
0
heshengli created
  • Exception message and full stack trace:An unhandled exception has occurred while executing the request. System.Security.Cryptography.CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Extensions.Logging.LoggingExtensions' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Win32.Registry, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

File name: 'Microsoft.Win32.Registry, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' --- End of inner exception stack trace --- at Microsoft.Extensions.Logging.LoggingExtensions.ErrorOccurredWhileRefreshingKeyRing(ILogger logger, Exception exception) at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow, Boolean forceRefresh) at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[] plaintext) --- End of inner exception stack trace --- at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[] plaintext) at Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.<>c__DisplayClass9_0.<<PersistStateAsync>g__PersistState|1>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.<>c__DisplayClass9_0.<<PersistStateAsync>g__PauseAndPersistState|0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Components.Endpoints.EndpointHtmlRenderer.PrerenderPersistedStateAsync(HttpContext httpContext) at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context) at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context) at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<<InvokeAsync>b__10_0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger) at Volo.Abp.AspNetCore.Serilog.AbpSerilogMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location --- at Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location --- at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Volo.Abp.AspNetCore.Security.Claims.AbpDynamicClaimsMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location --- at Volo.Abp.AspNetCore.Uow.AbpUnitOfWorkMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location --- at Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Builder.ApplicationBuilderAbpOpenIddictMiddlewareExtension.<>c__DisplayClass0_0.<<UseAbpOpenIddictValidation>b__0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Volo.Abp.AspNetCore.Security.AbpSecurityHeadersMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location --- at Volo.Abp.AspNetCore.Tracing.AbpCorrelationIdMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)

  • Steps to reproduce the issue:
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

5 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • This exception is not an ABP-specific bug; it’s coming from ASP.NET Core Data Protection during Blazor Server prerendering/persisted state (ComponentStatePersistenceManager.PersistStateAsync()), when it tries to encrypt data:

      • CryptographicException: ... encrypt the provided data
      • Inner exception: Could not load file or assembly 'Microsoft.Win32.Registry, Version=8.0.0.0'
    • The reason Swagger works but “the page” fails is that Swagger is just serving middleware/UI and usually doesn’t hit Blazor Server prerender persistence. The Blazor page pipeline does, so it triggers Data Protection encryption.

    Fix (recommended)

    1. Ensure the app is running with the full .NET 8 runtime (not trimmed / not missing framework assemblies).

      • This error typically happens when deploying in an environment/container where the Microsoft.Win32.Registry runtime assembly isn’t available (common with certain Linux/container publish setups or incorrect runtime installation).
    2. If you deploy with Docker, use an official ASP.NET 8 runtime base image (so the runtime packs include needed assemblies), e.g. mcr.microsoft.com/dotnet/aspnet:8.0 (or matching patch).

      • Rebuild and redeploy after switching base image.
    3. Configure Data Protection key storage explicitly (especially for IIS/containers), so key ring operations don’t rely on defaults that may differ per environment.

      • In your *.Web (Blazor Server) project module or Program.cs, configure DataProtection to persist keys to a known folder (mounted volume in containers; writable folder in IIS):
    using Microsoft.AspNetCore.DataProtection;
       using System.IO;
    
       builder.Services.AddDataProtection()
           .PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(builder.Environment.ContentRootPath, "DataProtection-Keys")));
    
    1. Make sure the app process identity can read/write that folder.
      • IIS: grant write permission to the AppPool identity for DataProtection-Keys (or your chosen path).

    If you are on IIS and also using OpenIddict certificates (common in ABP templates)

    If you are also loading openiddict.pfx in production, ensure IIS can load the cert and the private key correctly (this often requires Load User Profile = true and/or key storage flags). ABP has a dedicated guidance for this scenario and it’s closely related to crypto failures on IIS.


    Sources

    • https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/introduction
    • https://abp.io/docs/latest/solution-templates/layered-web-application/deployment/deployment-iis
    • https://abp.io/docs/latest/solution-templates/layered-web-application/deployment/openiddict-deployment
    • https://abp.io/community/articles/0znavo8r

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    heshengli created

    就是采用docker发布,和采用了redis的方式DataProtection,builder.Services.AddDataProtection() .PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(builder.Environment.ContentRootPath, "DataProtection-Keys")));

    依然报上面的错误

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Hi,

    Looking at the stack trace, the AuthServer page fails because ASP.NET Core DataProtection can't load Microsoft.Win32.Registry, 8.0.0.0. That's also why Swagger works but Blazor pages and the OpenIddict login page don't — Swagger doesn't touch DataProtection, while Blazor Server (ComponentStatePersistenceManager.PersistStateAsync) and the antiforgery cookie both go through IDataProtector.Protect and hit the same failing code path.

    This is almost certainly a deployment / publish issue rather than an ABP code issue. The usual causes are:

    • PublishTrimmed / PublishSingleFile / PublishAot stripping the transitive dll
    • The deployment folder missing the file after a manual copy
    • A container base image (alpine / chiseled) without it
    • A corrupted or 0-byte Microsoft.Win32.Registry.dll

    Before we ask for the full project, could you share these four small files from your published output? They are usually enough to pinpoint it:

    1. <YourApp>.AuthServer.deps.json
    2. <YourApp>.AuthServer.runtimeconfig.json
    3. A DLL list of your publish folder:
    # Linux / container
    find /path/to/publish -name "*.dll" | sort > dlls.txt
    
    # Windows PowerShell
    Get-ChildItem -Path C:\path\to\publish -Recurse -Filter *.dll |
      Select-Object -ExpandProperty FullName | Sort-Object > dlls.txt
    
    1. Your <YourApp>.AuthServer.csproj (or just the <PropertyGroup> and <ItemGroup> blocks)

    It would also help if you can confirm:

    • Where it runs (local dotnet run, IIS, Linux container, Azure App Service, etc.)
    • If it's a container, the base image (e.g. mcr.microsoft.com/dotnet/aspnet:8.0, ...:8.0-alpine, chiseled)
    • Whether a fresh project from the same template reproduces it, or only this one

    You can attach the files here, or email them to liming.ma@volosoft.com if you don't want to share them publicly.

    Thanks

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    heshengli created

    .AuthServer.deps.json 有Microsoft.Win32.Registry.dll,但是linux x64发布,发布程序文件中不包含此文件,然后采用docker compose 以docker 发布。出现这个问题后,重启docker也自动回复了

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Hi,

    linux-x64 publish 没有 Microsoft.Win32.Registry.dll 是正常的,这个包是 Windows 注册表 API 的 placeholder,linux 平台本来就不会复制 dll,不是你部署掉了文件。

    真正崩的地方在 ErrorOccurredWhileRefreshingKeyRing,意思是 DataProtection 刷新 key ring 已经失败了,再去打 error 日志的时候 logger 的 type init 又因为引用了 Microsoft.Win32.Registry 类型崩了。所以你看到的 dll 找不到是后面的错,前面 key ring 刷新失败的真错被盖住了。

    你说重启 docker 就恢复了,这个细节挺关键,多半是第一次启动 Redis 还没就绪 AuthServer 就跑起来了,key ring 第一次刷新失败;重启的时候 Redis 已经 ready 了,就正常。

    为了确认,麻烦发一下:

    1. docker-compose.yml 里 AuthServer + Redis 那部分(脱敏),主要看 depends_on / healthcheck
    2. AuthServer 从启动到第一次报错那段完整日志,看 Microsoft.AspNetCore.DataProtection.*StackExchange.Redis 有没有 warning / error
    3. Program.csAuthServerModule.cs 里 DataProtection 的配置代码,你之前同时说了 Redis 和 PersistKeysToFileSystem,到底用哪个
    4. 如果是 PersistKeysToFileSystemDataProtection-Keys 目录在容器里有没有挂 volume,没挂的话每次重启 key 都会重置

    也可以先试下让 AuthServer 等 Redis 健康再启动:

    services:
      auth-server:
        depends_on:
          redis:
            condition: service_healthy
    
      redis:
        image: redis:7-alpine
        healthcheck:
          test: ["CMD", "redis-cli", "ping"]
          interval: 5s
          timeout: 3s
          retries: 10
    

    首次启动就正常的话,基本就是这个原因。

    不方便贴可以发邮件 liming.ma@volosoft.com。

    Thanks

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.