Duplicate ASPNETCORE_Environment present for InProcess hosting causes ASPNET CORE 2.2 fails to load appsettings
See original GitHub issueAfter 2 days trying to figure out, i think i discovered a bug:
- I already had set manually the ASPNETCORE_ENVIRONMENT on Windows Server 2016 environment variables.
- 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>
- 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:
- Created 5 years ago
- Reactions:1
- Comments:9 (1 by maintainers)
By default, running a site in Visual Studio in IIS Express will add an
ASPNETCORE_ENVIRONMENT
variable set toDevelopment
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.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.