Open Closed

API no longer initializes correctly: missing Swagger/Angular UI, missing ClientId, and default admin user not created #10184


User avatar
0
Belen.molinaMA created

Hello, I am working on an ABP project (version Pro - Team License). Yesterday everything worked perfectly: I created new entities, generated migrations, updated the database, ran the API, and both Swagger and the Angular UI loaded without issues. I could log in normally using the default admin user.

Today, after reopening the solution, the API behaves unexpectedly:

Swagger and the Angular logo no longer appear when running the API. It looks like the application is not initializing properly.

When I try to log in, I receive an error saying that the ClientId is missing, as if the default OpenIddict client was never seeded.

I tried dropping and recreating the database (using Update-Database):

Sometimes it works, sometimes it does not.

Most of the time, the default admin user is NOT created, which should happen during the DataSeeder execution.

I did not change anything related to authentication, database configuration, or appsettings between yesterday and today.

It seems like:

the DataSeeder is not being executed reliably,

or the project is not connecting to the database during startup,

or OpenIddict initialization is failing silently, causing the Client and admin user seeding to be skipped.

Could you help me understand why the initialization is inconsistent and why the default admin user and default clients are not being created when recreating the DB?

Thank you.


5 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution Below is a complete checklist to make ABP’s initialization deterministic again (Swagger/UI visible, OpenIddict client present, admin user created). It focuses on ensuring the Db connection is correct, migrations are applied, and that data seeding is always executed and not skipped.

    A) Always run migrations + seed via DbMigrator first

    • Set the DbMigrator project as startup and run it. It will:
      • Apply all EF Core migrations for all modules.
      • Execute all IDataSeedContributors (creates default admin user, roles, OpenIddict clients like Swagger/Angular).
    • If you frequently drop and recreate the DB, always re-run DbMigrator before running the API host.

    B) Verify the connection string used by all processes

    • Ensure the same ConnectionStrings:Default is used by:
      • DbMigrator
      • HttpApi.Host (and AuthServer if separated)
    • A common cause of “seeding sometimes works”: DbMigrator seeds one database, but the API points to another (e.g., appsettings.Development.json vs appsettings.json or User Secrets). Align these and restart.

    C) Ensure seeding is invoked if you rely on hosts (not only DbMigrator)

    • In some solutions, hosts do not seed by default. If you expect seeding on API start (not recommended for prod), explicitly invoke IDataSeeder once:
    public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
      {
          var seeder = context.ServiceProvider.GetRequiredService<IDataSeeder>();
          await seeder.SeedAsync(); // idempotent; safe to call
      }
    
    • Prefer DbMigrator for consistent results; only use the above during local dev if needed.

    D) Confirm your IDataSeedContributor discovery

    • Each custom contributor must be in a loaded module and registered as:
    public class MyDataSeedContributor : IDataSeedContributor, ITransientDependency
      {
          public async Task SeedAsync(DataSeedContext context)
          {
              // idempotent seeding
          }
      }
    
    • If a contributor is in a project that the host/DbMigrator doesn’t depend on, it won’t run. Add the module dependency to the host/DbMigrator module via [DependsOn(...)]. This is a common reason for “admin not created/client not seeded.”

    E) Check OpenIddict client seeding inputs

    • ABP Commercial templates seed OpenIddict applications (clients) from configuration. Verify your seeder reads from the correct section (e.g., "OpenIddict:Clients" or similar) and that your appsettings in DbMigrator contains:
      • Swagger client
      • Angular/SPA client
      • Correct RootUrl/RedirectUris for your current ports
    • After DB recreate, if ClientId missing arises, it typically means OpenIddict seeder didn’t run or read empty values from configuration. Keep client config in the DbMigrator appsettings.json and re-run.

    F) Ensure migrations include all module tables

    • If logs show “Invalid object name 'Abp...'” it means migrations weren’t applied (or the wrong DB is used).
    • Re-run DbMigrator and check logs for success.
    • If you added optional/pro modules, ensure the corresponding EFCore modules are referenced and included in DbMigrator so their migrations are applied.

    G) Swagger/Angular UI missing on API

    • Confirm you didn’t accidentally disable the middleware:
    app.UseAbpSwaggerUI(options =>
      {
          options.SwaggerEndpoint("/swagger/v1/swagger.json", "My API");
      });
    
    • Ensure environment is Development or your code doesn’t conditionally skip UseAbpSwaggerUI in non-dev.
    • If ports changed, update Angular environment oAuthConfig (issuer, redirectUri, clientId/scope) to match OpenIddict client entries and API SelfUrl/CORS/RedirectAllowedUrls in HttpApi.Host appsettings.

    H) Make seeding resilient and repeatable

    • Implement seeding idempotently (check existence before insert).
    • Use DataSeedContext correctly (host vs tenant). If multi-tenancy is on and you expect tenant data, seed per-tenant in DbMigrator by iterating tenants and calling IDataSeeder.SeedAsync(new DataSeedContext(tenantId)).

    I) Quick local recovery steps

    1. Stop API/Auth.
    2. Drop database.
    3. Ensure DbMigrator appsettings.json has:
      • Correct ConnectionStrings:Default.
      • OpenIddict client config sections (Swagger/Angular).
    4. Run DbMigrator once. Confirm in DB:
      • Users table has admin.
      • OpenIddictApplications has SPA/Swagger clients.
    5. Run HttpApi.Host. Visit /swagger and login via Angular.
    6. If “ClientId missing” persists, verify that the exact ClientId in Angular environment matches the ClientId seeded into OpenIddictApplications and that RedirectUris match the current Angular url (http/https, port).
    1. Sources
    • General ABP references:
      • https://github.com/abpframework/abp
    • ABP CLI (validated):
      • https://docs.abp.io/en/abp/latest/CLI

    This approach aligns with common ABP conventions, but specific official documentation for every point in this exact scenario is not available.


    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.

  • User Avatar
    0
    Belen.molinaMA created

    Thank you — the checklist you provided resolved my issue for now. Running the DbMigrator first and aligning all connection strings fixed the inconsistent initialization and the missing admin/client records.

    I have one additional question:

    How should I properly regenerate the client-side proxies after creating a new application service?

    In previous ABP versions I used commands like:

    abp generate-proxy
    

    or (for Angular)

    abp generate-proxy -t ng
    

    But I want to confirm the correct and recommended way in the current framework version, especially when using Angular + HttpApi.Host.

    • Should I run the command from the Angular project folder or from the solution root?
    • Are there any configuration steps required to make sure the new services appear in the proxy generator?
    • How do I force regeneration if the proxy is not detecting new endpoints?

    Thanks again for your help — your previous guidance was very useful.

  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution Here’s the definitive and current way to regenerate Angular client-side proxies for your new application services.
    • Where to run the command

      • Run from the Angular app root folder (the folder that contains package.json), not from the solution root.
      • Ensure the backend (HttpApi.Host) is running and reachable while generating.
    • The command to use (Angular)

      • Basic (auto-detects the default API endpoint exposed by the running backend): abp generate-proxy -t ng
      • If your API is not reachable via the default discovery URL, specify the backend URL explicitly: abp generate-proxy -t ng -u https://localhost:44367
      • For modular/advanced scenarios, you can target a specific module via: abp generate-proxy -t ng -m MyCompany.MyModule -u https://localhost:44367
    • Prerequisites and configuration that affect detection

      • Backend must run (prefer dotnet run instead of VS IIS Express when generating).
      • Angular app should have:
        • @abp/ng.schematics in devDependencies.
        • environment.apis.default.url correctly pointing to your backend URL (commonly your HttpApi.Host).
        • environment.apis.default.rootNamespace set to your solution’s root namespace (prevents deep folder nesting).
        • tsconfig path mappings for @proxy and @proxy/* if you want nice imports.
    • Forcing regeneration or when new endpoints are not detected

      • Make sure your new app services are exposed by auto API controllers (Application services derived from ApplicationService are auto-exposed unless explicitly disabled).
      • Restart the backend so the contract endpoint reflects new services.
      • Clear generated proxies if needed (delete src/app/proxy) and run: abp generate-proxy -t ng -u https://localhost:44367
      • If using multiple APIs or different API names, add/verify the apiName in the generated services (defaults to "Default") and ensure the backend’s remote service name matches (Configure<AbpRemoteServiceOptions> if customized).
    • Notes for reliable results

      • Keep ABP CLI up-to-date: dotnet tool update -g Volo.Abp.Cli
      • If you run into Visual Studio/IIS Express limitations, stop it and run HttpApi.Host with dotnet run, then generate again.
      • If the Angular project cannot reach the backend during generation (network/port mismatch), the generator won’t see new endpoints—always verify the URL and port with -u.
    1. Sources
    • Angular Service Proxies (how to generate and where to run):
      • https://docs.abp.io/en/abp/latest/UI/Angular/Service-Proxies
    • ABP CLI (installation/update/usage):
      • https://docs.abp.io/en/abp/latest/CLI

    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.

  • User Avatar
    0
    Belen.molinaMA created

    Thank you, everything is working correctly now.

    One more question: Where can I find the backend logs generated by ABP? I would like to inspect runtime errors coming from the HttpApi.Host and the application layer.

  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution ABP uses ASP.NET Core logging with Serilog pre-configured in the startup templates. By default:
    • Where to see logs during development

      • Console: visible in the HttpApi.Host output (dotnet run or VS output).
      • File: Serilog writes rolling files under a Logs folder in the host’s content root. Typical path:
        • src/YourProject.HttpApi.Host/Logs/logs-<date>.txt
        • If IIS Express is used, the content root may be under the IISExpress working directory; prefer dotnet run to keep logs under the project folder.
    • How to confirm or change the file location

      • Check appsettings.json (and appsettings.Development.json) in HttpApi.Host for Serilog configuration. The File sink path (or rolling file) controls where logs are written. Example keys:
        • "Serilog": { "WriteTo": [ { "Name": "File", "Args": { "path": "Logs/logs.txt", ... } }, ... ] }
      • Adjust path to an absolute or relative directory of your choice and restart the host.
    • Increasing verbosity to capture errors

      • In appsettings.Development.json, set MinimumLevel and per-source overrides, e.g.:
        • "Serilog": { "MinimumLevel": { "Default": "Information", "Override": { "Microsoft": "Warning", "Volo": "Debug" } } }
      • Restart the host to apply.
    • Production recommendations

      • ABP recommends using a durable sink (e.g., Elasticsearch, Seq, database) instead of plain files in production. Add/change Serilog sinks in appsettings.json and deploy with appropriate volumes/paths.
    • Quick checklist

      • Run HttpApi.Host with dotnet run and reproduce the issue; check Console and Logs folder.
      • Verify Serilog:WriteTo section exists in HttpApi.Host appsettings(.Development).json.
      • If no Logs folder appears, ensure the File/Async sinks are configured and the process has write permission to the folder.
    1. Sources
    • ABP logging overview:
      • https://docs.abp.io/en/abp/latest/Logging
    • Deployment note (Serilog included; writes to file and console by default):
      • https://abp.io/docs/latest/deployment/configuring-production

    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.

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.1.0-preview. Updated on December 05, 2025, 12:34
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.