Aspnetcore: ASP.NET Core 1.1 IIS Deployment Issue

Created on 6 Dec 2016  Â·  12Comments  Â·  Source: dotnet/aspnetcore

Hello,

There is a MVC web app that we are attempting to publish to IIS on Windows Server 2008 R2 SP 1. Previously we were deploying our web app using .NET Core RC1 and .NET Core 1.0 fine on the same server and it started and ran without such issues.

However having upgraded to .NET Core 1.1 we are getting some issues getting the application to run on the same server. We have installed the .NET Core 1.1 runtime on the server and configured the web app in IIS as documented here: https://docs.microsoft.com/en-us/aspnet/core/publishing/iis

After deploying to the server and attempting to run it we were first getting this error in the browser window:

HTTP Error 502.5 - Process Failure
Common causes of this issue:

    The application process failed to start
    The application process started but then stopped
    The application process started but failed to listen on the configured port 

Troubleshooting steps:

    Check the system event log for error messages
    Enable logging the application process’ stdout messages
    Attach a debugger to the application process and inspect 

For more information visit: http://go.microsoft.com/fwlink/?LinkID=808681

After some research we changed the web.config on the deployed web app as follows:

From:

<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>

To:

<aspNetCore processPath="dotnet" arguments=".\MyWebApp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>

Now we get this error in the browser window:

An error occurred while starting the application.

.NET Core X64 v4.1.1.0    |   Microsoft.AspNetCore.Hosting version 1.1.0-rtm-22752    |    Microsoft Windows 6.1.7601 S    |   Need help? 

It also started error logging to the /logs/ folder. The error from these logs is:

Application startup exception: System.DllNotFoundException: Unable to load DLL 'api-ms-win-core-registry-l1-1-0.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Interop.mincore.RegOpenKeyEx(SafeRegistryHandle hKey, String lpSubKey, Int32 ulOptions, Int32 samDesired, SafeRegistryHandle& hkResult)
   at Microsoft.Win32.RegistryKey.InternalOpenSubKeyCore(String name, RegistryRights rights, Boolean throwOnPermissionFailure)
   at Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver.ResolveDefaultPolicy()
   at Microsoft.Extensions.DependencyInjection.DataProtectionServices.<GetDefaultServices>d__0.MoveNext()
   at Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAdd(IServiceCollection collection, IEnumerable`1 descriptors)
   at Microsoft.Extensions.DependencyInjection.DataProtectionServiceCollectionExtensions.AddDataProtection(IServiceCollection services)
   at Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions.AddAuthentication(IServiceCollection services)
   at Microsoft.Extensions.DependencyInjection.IdentityServiceCollectionExtensions.AddIdentity[TUser,TRole](IServiceCollection services, Action`1 setupAction)
   at MyWebApp.Startup.ConfigureServices(IServiceCollection services) in C:\MyWebApp\Startup.cs:line 49
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Hosting environment: Production
Content root path: C:\inetpub\wwwroot\mywebapp
Now listening on: http://localhost:47113
Application started. Press Ctrl+C to shut down.

The error that it mentions "at MyWebApp.Startup.ConfigureServices(IServiceCollection services) in C:MyWebAppStartup.cs:line 49" refers to the line below in Startup.cs:
```c#
services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

ApplicationDbContext was auto-generated by Visual Studio 2015 (Update 3) for the ASP.NET authentication and login functionality. This line of code was commented out and the web app re-deployed, but then it gave the same error for this line in Startup.cs: 
```c#
services.AddMvc();

Microsoft Visual C++ 2015 Redistributable (x64) 14.0.24212 is installed on the server. This web app runs fine without such errors locally.

Any ideas as to what is causing this and how it could be resolve? Thank you.

Most helpful comment

For future reference for myself or anyone else who is getting the "an error occurred while starting the application" error, that a likely reason is that you are missing the appsettings.Environment.json for the environment that you have set in your app properties.

All 12 comments

It's having trouble with Data Protection key ring access. Did you run the script to create the DP hive ...

https://docs.microsoft.com/en-us/aspnet/core/publishing/iis#create-a-data-protection-registry-hive

... and I suppose you'll have a dep on Microsoft.AspNetCore.Antiforgery (or just the DP package). I'm not sure which package, and that's something to think about for the IIS doc, where we aren't clear on it.

cc/ @blowdart

@GuardRex Thanks for the feedback. I tried to run the script after you mentioned it. However there was an error:

Unable to find type [Microsoft.Win32.RegistryView]: make sure that the assembly containing this type is loaded.
At C:\Users\russ\Downloads\scripts\Provision-AutoGenKeys.ps1:27 char:50
+         $regView = [Microsoft.Win32.RegistryView] <<<< ::Registry32;
    + CategoryInfo          : InvalidOperation: (Microsoft.Win32.RegistryView:String) [], ParentContainsErrorRecordExc
   eption
    + FullyQualifiedErrorId : TypeNotFound

I suggest closing here and moving this issue over to Data Protection repo at https://github.com/aspnet/DataProtection/issues, where you'll get more DP guru :eyes: eyes :eyes: on it. You are close tho to getting it sorted. It just looks like it doesn't have the right package. WRT the error you just received :point_up: that's a good one for them to see, too. I haven't heard of that happening in my travels.

Okay great, thank you for the feedback. I might open a new issue there for the Power Shell error and reference this issue so that I don't need to re-enter it. Plus someone else here may have come across this too.

@rasikaw-is I just want to say that your original post was a work of art. 😃 Thank you so much for providing all the troubleshooting steps -- the bit about setting stdoutLogEnabled="true" finally helped me nail down a similar production issue that has been plaguing me for hours.

For future reference for myself or anyone else who is getting the "an error occurred while starting the application" error, that a likely reason is that you are missing the appsettings.Environment.json for the environment that you have set in your app properties.

@Serjster can confirm this exact behavior. When in doubt, double check a template. Thanks for writing this down as it was quite searchable!

What is the resolution for this ? Is there a common reason ?

@umeshbapat If you mean regarding the presence of an appsettings file, using the CreateDefaultBuilder today (2.x bits) makes the appsettings files optional. An app might be missing a setting, but a missing file shouldn't :boom:. See the Hosting topic for more info on CreateDefaultBuilder; the Hosting topic is updated for 2.0. CreateDefaultBuilder is at :point_right: https://github.com/aspnet/MetaPackages/blob/dev/src/Microsoft.AspNetCore/WebHost.cs#L157-L158

Thanks @guardrex but I was referring to main thread of the discussion. I feel there are couple or more different answers and the most accepted answer (appsettings being absent) is also not helping with this.

If you mean a general 502.5 situation, try the Troubleshooting section of the Publishing to IIS topic. Most of the 502.5 causes are listed (they appear in the Browser entry for each potential problem). Yes, there are several situations that can hit it in hosting, but it can also happen if the app fails to start for some reason.

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.

Was this page helpful?
0 / 5 - 0 ratings