question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicate ASPNETCORE_Environment present for InProcess hosting causes ASPNET CORE 2.2 fails to load appsettings

See original GitHub issue

After 2 days trying to figure out, i think i discovered a bug:

  1. I already had set manually the ASPNETCORE_ENVIRONMENT on Windows Server 2016 environment variables.
  2. After 2.2 release, i decided to update the publish profile .pubxml to include the desired environment, for instance:

<EnvironmentName>Development</EnvironmentName>

This generates the web.config:

<aspNetCore processPath="dotnet" arguments=".\TJPA.CentralBoletos.API.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
   <environmentVariables>
           <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
   </environmentVariables>
</aspNetCore>
  1. When i published the application, the application wont startup, specifically when reading the connection string for the HangfireDB schema i was using.

In Web browser says:

An error occurred while starting the application. .NET Core 4.6.27110.04 X64 v4.0.0.0 | Microsoft.AspNetCore.Hosting version 2.2.0-rtm-35687 | Microsoft Windows 10.0.14393 | Need help?

In std logs:

Application startup exception: System.ArgumentNullException: Value cannot be null. Parameter name: nameOrConnectionString at Hangfire.SqlServerStorageExtensions.UseSqlServerStorage(IGlobalConfiguration configuration, String nameOrConnectionString, SqlServerStorageOptions options) at TJPA.CentralBoletos.API.Startup.<>c__DisplayClass5_0.<ConfigureServices>b__2(IGlobalConfiguration config) in C:\GIT\central-boletos\api-central-boletos\TJPA.CentralBoletos.API\Startup.cs:line 52 at Hangfire.HangfireServiceCollectionExtensions.<>c__DisplayClass0_0.<AddHangfire>b__9(IServiceProvider serviceProvider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Hangfire.HangfireApplicationBuilderExtensions.ThrowIfNotConfigured(IApplicationBuilder app) at Hangfire.HangfireApplicationBuilderExtensions.UseHangfireServer(IApplicationBuilder app, BackgroundJobServerOptions options, IEnumerable`1 additionalProcesses, JobStorage storage) at TJPA.CentralBoletos.API.Startup.ConfigurarHangfireServer(IApplicationBuilder app, IServiceProvider serviceProvider) in C:\GIT\central-boletos\api-central-boletos\TJPA.CentralBoletos.API\Startup.cs:line 149 at TJPA.CentralBoletos.API.Startup.Configure(IApplicationBuilder app, IServiceProvider serviceProvider) in C:\GIT\central-boletos\api-central-boletos\TJPA.CentralBoletos.API\Startup.cs:line 79 — End of stack trace from previous location where exception was thrown — at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() Hosting environment: Development;Development Content root path: C:\inetpub\wwwroot\central-boletos Application started. Press Ctrl+C to shut down.

The ancm log:

[aspnetcorev2.dll] Initializing logs for ‘C:\Program Files\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll’. Process Id: 10784… File Version: 12.2.18316.0. Description: IIS ASP.NET Core Module V2. Commit: ce8cf65589734f82b0536c543aba5bd60d0a5a98. [aspnetcorev2.dll] Resolving hostfxr parameters for application: ‘dotnet’ arguments: ‘TJPA.CentralBoletos.API.dll’ path: 'C:\inetpub\wwwroot\central-boletos' [aspnetcorev2.dll] Known dotnet.exe location: ‘’ [aspnetcorev2.dll] Process path ‘dotnet.exe’ is dotnet, treating application as portable [aspnetcorev2.dll] Resolving absolute path to dotnet.exe from ‘dotnet.exe’ [aspnetcorev2.dll] Invoking where.exe to find dotnet.exe [aspnetcorev2.dll] where.exe invocation returned: 'C:\Program Files\dotnet\dotnet.exe C:\Program Files (x86)\dotnet\dotnet.exe ’ [aspnetcorev2.dll] Current process bitness type detected as isX64=1 [aspnetcorev2.dll] Processing entry ‘C:\Program Files\dotnet\dotnet.exe’ [aspnetcorev2.dll] Binary type 6 [aspnetcorev2.dll] Found dotnet.exe via where.exe invocation at ‘C:\Program Files\dotnet\dotnet.exe’ [aspnetcorev2.dll] Resolving absolute path to hostfxr.dll from ‘C:\Program Files\dotnet\dotnet.exe’ [aspnetcorev2.dll] hostfxr.dll located at ‘C:\Program Files\dotnet\host\fxr\2.2.0\hostfxr.dll’ [aspnetcorev2.dll] Converted argument ‘TJPA.CentralBoletos.API.dll’ to ‘C:\inetpub\wwwroot\central-boletos\TJPA.CentralBoletos.API.dll’ [aspnetcorev2.dll] Parsed hostfxr options: dotnet location: ‘C:\Program Files\dotnet\dotnet.exe’ hostfxr path: ‘C:\Program Files\dotnet\host\fxr\2.2.0\hostfxr.dll’ arguments: [aspnetcorev2.dll] Argument[0] = ‘C:\Program Files\dotnet\dotnet.exe’ [aspnetcorev2.dll] Argument[1] = ‘C:\inetpub\wwwroot\central-boletos\TJPA.CentralBoletos.API.dll’ [aspnetcorev2.dll] c:\b\w\e37dd45d8cd1eaf4\src\iisintegration\src\aspnetcoremodulev2\commonlib\fileoutputmanager.cpp:142 Operation failed with LastError: 32 HR: 0x80070020 [aspnetcorev2.dll] Loading request handler: ‘C:\inetpub\wwwroot\central-boletos\runtimes\win-x64\nativeassets\netcoreapp2.2\aspnetcorev2_inprocess.dll’ [aspnetcorev2.dll] Creating handler application [aspnetcorev2_inprocess.dll] Initializing logs for ‘C:\inetpub\wwwroot\central-boletos\runtimes\win-x64\nativeassets\netcoreapp2.2\aspnetcorev2_inprocess.dll’. Process Id: 10784… File Version: 12.2.18316.0. Description: IIS ASP.NET Core Module V2 Request Handler. Commit: ce8cf65589734f82b0536c543aba5bd60d0a5a98. [aspnetcorev2_inprocess.dll] Waiting for initialization [aspnetcorev2_inprocess.dll] Starting in-process worker thread [aspnetcorev2_inprocess.dll] Resolving hostfxr parameters for application: ‘dotnet’ arguments: ‘TJPA.CentralBoletos.API.dll’ path: 'C:\inetpub\wwwroot\central-boletos' [aspnetcorev2_inprocess.dll] Known dotnet.exe location: ‘C:\Program Files\dotnet\dotnet.exe’ [aspnetcorev2_inprocess.dll] Process path ‘dotnet.exe’ is dotnet, treating application as portable [aspnetcorev2_inprocess.dll] Resolving absolute path to hostfxr.dll from ‘C:\Program Files\dotnet\dotnet.exe’ [aspnetcorev2_inprocess.dll] hostfxr.dll located at ‘C:\Program Files\dotnet\host\fxr\2.2.0\hostfxr.dll’ [aspnetcorev2_inprocess.dll] Converted argument ‘TJPA.CentralBoletos.API.dll’ to ‘C:\inetpub\wwwroot\central-boletos\TJPA.CentralBoletos.API.dll’ [aspnetcorev2_inprocess.dll] Parsed hostfxr options: dotnet location: ‘C:\Program Files\dotnet\dotnet.exe’ hostfxr path: ‘C:\Program Files\dotnet\host\fxr\2.2.0\hostfxr.dll’ arguments: [aspnetcorev2_inprocess.dll] Argument[0] = ‘C:\Program Files\dotnet\dotnet.exe’ [aspnetcorev2_inprocess.dll] Argument[1] = ‘C:\inetpub\wwwroot\central-boletos\TJPA.CentralBoletos.API.dll’ [aspnetcorev2_inprocess.dll] In-process callbacks set [aspnetcorev2_inprocess.dll] Event Log: 'Application ‘C:\inetpub\wwwroot\central-boletos' started the coreclr in-process successfully.’ End Event Log Message. [aspnetcorev2_inprocess.dll] Starting app_offline monitoring in application 'C:\inetpub\wwwroot\central-boletos' [aspnetcorev2_inprocess.dll] Starting file watcher thread

When i removed the lines in web.config solved the problem:

   <environmentVariables>
           <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
   </environmentVariables>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
phollycommented, Dec 21, 2018

By default, running a site in Visual Studio in IIS Express will add an ASPNETCORE_ENVIRONMENT variable set to Development in web.config if a web.config exists in the project folder. When the project gets published that environment variable will still be there in web.config. So if web.config overrides other environmental variables then that would be a problem. But maybe the problem is with IIS Express adding that variable.

1reaction
milendimocommented, Mar 15, 2019

As a workaround, you’d set the ASPNETCORE_ENVIRONMENT variable as either in OS environment variables or in your configuration files. Having it defined in more than one location would cause the behavior as decried above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot ASP.NET Core on Azure App Service and IIS
A common failure condition is the app is misconfigured due to targeting a version of the ASP.NET Core shared framework that isn't present....
Read more >
ASP.NET Core deployment to IIS error: Development ...
First, check the value of ASPNETCORE_ENVIRONMENT variable. You will have to set this environment variable to "Production" (or other ...
Read more >
ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1
The cause of a process startup failure can usually be determined from entries in the Application Event Log and the ASP.NET Core Module...
Read more >
HTTP Error 500.30 - ASP.NET Core app failed to start help
A common problem for startup problems with ASP.NET Core is an invalid appsettings.json and/or appsettings.Production.json . It could be either a ...
Read more >
Why isn't my ASP.NET Core environment-specific ...
In this post I describe an issue I was having in which my application wouldn't load my appsettings.Development.json file when running in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found