HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure after upgrading to ASP.NET Core 2.2
Asked Answered
F

38

106

After upgrading my project to ASP.NET Core 2.2, I tried to run the application (locally of course) and the browser displayed an error message like in the below screenshot.

enter image description here

no more errors notified by visual studio error explorer. I don't know what's happen.

Firstling answered 18/2, 2019 at 21:22 Comment(8)
You also need to upgrade .NET Core server bundle to the same version. You cannot only update your project, as that leads to version mismatch in ANCM.Naughton
@LexLi The issue corrupted local, not server. I've install dotnet-sdk-2.2.104 and aspnetcore-runtime-2.2.2.Firstling
Nope. You need the latest "Runtime & Hosting Bundle" from here dotnet.microsoft.com/download/dotnet-core/2.2Naughton
@LexLi thank you, for your answer.Firstling
If the publish "Target Runtime" is win-x64, your web.config should have something like: <aspNetCore processPath=".\YOUR_APP.exe" arguments=""' but if it's Portable it should be something like: <aspNetCore processPath="dotnet" arguments=".\YOUR_DLL.dll"Frontlet
@LexLi your suggestion works for me. ThanksHeard
In my case different target runtime are selected in different projects, when I selected it x64 which resolved my issue.Foulard
if you update the depended referenced libraries and only copy the main project dll to iis hosting directory then this kind of issue appears. Copy the whole project published folder to wwwroot to be in safe side.Nathalienathan
F
-3

My solution:

  • remove all projects with catalog
  • create new projects
  • copy all files but program.cs and startup.cs
  • manual copying from startup and program classes to new startup.cs and new program.cs

Works.

Firstling answered 20/2, 2019 at 17:44 Comment(1)
It may be a solution but it's a very "annoying" solution. I've never had to do this to fix an issue with a C# solution. Also, this error isn't usually related to the C# code itself but rather the server it is being hosted on.Discommode
E
45

In my case, I upgraded some nuget packages to net core 2.2, but I did not have the net core 2.2 sdk installed, so I went to net core website to download the latest sdk or runtime package, and then I did a net stop was /y and then a net start w3svc in the CMD as administrator. Problem solved for me.

Expletive answered 14/4, 2019 at 3:31 Comment(3)
that worked for me. Although on the server only the runtime should be required.Battue
Great answer. Worked perfectly, but I updated to the exact version that the project I'm implementing uses (that's not the latest one). Should be marked as correct answer.Millais
Downloaded proper sdk from MS site and it fixed it. Thanks!Girdler
P
20

I encountered this error after trying to publish from VS2017 to the production Windows 2016 server. (It worked fine in IIS Express on my local Win10 PC.)

I updated packages, all versions matching and updated in my code, .net core versions matching, restart IIS, rebooting... no joy.

In the Publish > Configure > Settings (left tab) I had to set the Target-runtime from "Portable" to "win-x64" (or whatever is relevant to your environment). I also opted to "Remove additional files at destination."

"Portable" is the default setting. I'm not sure what it takes for the "Portable" runtime to work properly, but might save someone else some time if a "Portable" runtime is not something you need.

enter image description here

Generally speaking, I get this error if something is mismatched in my environment. For example, one time I was upgrading one of my projects to .Net Core 3.1 from 2.2 and hadn't installed the ASP.NET Core Runtime Hosting Bundle on my server:

https://dotnet.microsoft.com/download/dotnet-core/3.1

Also, you can get this error if your Application Pool is set to True for Enable 32-Bit Applications. Try:

IIS Manager > Application Pools > app pool name > (right click) Advanced Settings > Enable 32-Bit Applications = False

Permenter answered 5/5, 2019 at 21:17 Comment(3)
perfect :) thanks a lot, i had to publish my application again.Esch
So annoying I had to do this change to win-x64 for my .net core 3.1 on the Windows 2016 ServerGest
this seemed to be it for me. it was additionally tricky since I'm using Rider and for some reason it will refuse to publish anything but Portable, but apparently Portable doesn't work when publishing ASP Core... I had to publish to a temp folder using VS and then manually copy the files to the web folder.Constantinople
F
18

I ran into this issue and had a different solution. For me it was that I had a package that was out of date with the application (I had updated it on NuGet, and the library hadn't been replaced in production). Updating the package fixed it for me.

Note with this: I had to manually run dotnet.exe with the project dll in order to see the message that fixed it for me.

Hope this helps someone else down the road.

Foreman answered 20/3, 2019 at 19:50 Comment(4)
Running $ dotnet ./project.dll indeed revealed the actual problem and fixing that obviously worked.Schappe
Running the command gave more information. I had the install the latest SDKFlattery
This is what helped me. I ran $ dotnet ./project.dll and then went to localhost:5000 as it suggested. Here I saw the error logs that led me to a solution. For me it was a syntax error in appsettings.Development.json. Go figure.Welladvised
running dotnet ./project dl works ! But IIS fails to run it :(Zanazander
T
14

you have 2 solution(this answer works on windows server I do not know anything about linux server).

first:

  • copy all folder(except bin and obj folder) of your project to server

  • open cmd in your project folder then run this command: dotnet run then all warning and error show to you(if you have error about above command not recognize download dot net core sdk from this link)

second:

  • you must changed hostingModel attribute from OutOfProcess to inprocess in web.config and you can change stdoutLogEnabled to true value for get your project error in logs folder
  • read your projects errors and fix those.

in my case web.config is:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\BMS.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
    </system.webServer>
  </location>
</configuration>

and I change it to:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\BMS.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>
Tracey answered 26/11, 2019 at 4:52 Comment(1)
That is not a solution for those who want to do the OutOfProcess way :-(Crystallization
Z
8

In my case it was the log level set incorrectly in the appsettings.json. Instead of Warning I've had Warn and this crashed the app with above error.

Zolnay answered 22/5, 2019 at 7:41 Comment(1)
Yea same here, I tried to find the problem and I saw comma is missing :(Publicness
M
8

Seems that everyone has a different answer for this. I also had this issue as well. There are many different things as you can tell that cause this issue. If you don't find any of these solutions helpful or have issues trying to go through all these different solutions, you can try running your application from the command line from the publish folder.

After publish, if you receive this error, go to your publish folder, and then open a command/terminal window, after that type dotnet .\YourStartupProject.dll, you should receive an exception error, which should make fixing the issue easier.

For example, this is an error I received on trying on a new environment without setting up a SQL server, and of course, would receive this error.

Application startup exception: System.Exception: Could not resolve a service of type 
'YourStartupProject.DataServices.DbContext.DbContext' for the parameter 
'context' of method 'Configure' on type 'YourStartupProject.Startup'. ---> 
System.ArgumentNullException: Value cannot be null.
Parameter name: connectionString

Once you resolve your error, try it again, rinse, repeat.

Malcom answered 20/4, 2020 at 13:23 Comment(0)
L
3

Another answer that might help other people in the same case: we have an AppService on Azure where there are 3 NETCore project deployed on 3 different path:

  • One for Web (/webapi)
  • One for Mobile (/mobileapi)
  • One for Functions serverless, in our case was it was AzureFunctions (/functionapi)

Since the upgrade to NETCore3.x, we understood that the hosting model by default was "In-Process" so we had to edit the .csproj file to explictly set the hosting model to "Out-Of-Process" like this:

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
  </PropertyGroup>

But it was not enough: in fact, we also have to edit Program.cs. Why ? Because in Program.cs the one generated by default in NETCore3.x you have the following code:

    public static IHostBuilder CreateHostBuilder(string[] args)
    {
        return Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
                webBuilder.ConfigureKestrel(o => o.AddServerHeader = false);
            });
    }

When we replaced this by the old code by NETCore2.x version like below:

    public static IWebHostBuilder CreateWebHostBuilder(string[] args)
    {
        return WebHost.CreateDefaultBuilder(args)
            .UseKestrel(options => options.AddServerHeader = false)
            .UseStartup<Startup>();
    }

After deployment, the error 502.5 ANCM Startup Failure was gone :) Hope this answer can help other people.

BTW I know this post is related to NETCore2.2, we also met the same problem but we decided to switch to NETCore3.1 because NETCore2.2 was no more supported and this version was also buggy on some other points.

Lenhard answered 15/8, 2020 at 7:40 Comment(0)
S
2

For me the issue was caused by dotnet publish creating a web.config entry stdoutLogFile=".\logs\stdout". The correct value should be stdoutLogFile="\\?\%home%\LogFiles\stdout".

MSDN reference: https://blogs.msdn.microsoft.com/waws/2018/06/10/troubleshooting-http-502-5-startup-issues-in-azure-appservice-for-asp-net-core-websites/

This could be a bug in the ASP.NET Core 2.2.0 runtime which may have been fixed in a later version.

Spheno answered 19/11, 2019 at 10:25 Comment(1)
Also had a similar problem, but in my codebase the stdoutLogFile was already set to a simple relative path .\stdout. That broke the app in Azure, but it was hard to catch. Sometimes worked, other times was crashing and giving out random FileNotFound errors about various .NET libraries. Changed the stdoutLogFile back to \\?\%home%\LogFiles\stdout in my project and works like a charm. Some error handling on their side!Birch
M
2

Follow this steps:

  • create a directory in root of your project : logs/stdout

  • open the web.config file from root of your project and find this line:

    <aspNetCore processPath=".\web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    
  • set stdoutLogEnabled as true and save it

  • reload your app and see the logs in the directory : logs/stdout

Molality answered 10/7, 2020 at 15:36 Comment(0)
T
1

I ran into this issue today with my hosting - locally everything is ok but once I publish, I get this error.

I looked through the packages and found out that some .net core stuff was upgraded to 3.0 preview.

Then I changed the build option in VS2019 from "Framework-Dependent" to "Self-contained". It took 5 times longer to build and publish but now it works.

Now I'm checking with host tech support what might be an issue - officially they support 2.1 / 2.2 only, so this might be these packages from 3.0 Preview, however target build is 2.2.

Tannenwald answered 18/5, 2019 at 18:5 Comment(0)
A
1

My issues was malformed appsetttings.json file. I enabled standard out logging via web.config and was able to get the underlying exception throwing this error.

Ake answered 23/7, 2019 at 19:21 Comment(0)
G
1

If resetting the project and manually copying Program and Startup classes worked for you, then something was clearly messed up. There are some bigger underlying problems with this. Using the OutOfProcess hosting model is okay, but with .Net Core 2.2 you should be able to use the InProcess hosting model, since it is naturally faster: everything is processed in IIS, without an extra HTTP-hop between IIS and your app's Kestrel server.

If you right-click your project file in the visual studio solution explorer, please make sure that AspNetCoreModuleName tag has AspNetCoreModuleV2 value (as opposed to the older AspNetCoreModule). Also, examine Windows Application Event Log to identify the potential culprit. Even though error messages there are somewhat cryptic, they might point you to the exact line number in the code that caused the failure.

Finally, in case you use CI/CD with TFS, there may be environment variable(s) in appsettings.json file that were not properly replaced with the actual values (URLs, etc.).

Glennglenna answered 28/8, 2019 at 23:38 Comment(0)
J
1

Looks like i had the same issue. It's happens because if you don't have global.json file in solution, then VS build(publish) .net core app with the last version that installed on your pc. So, i do the next solution:

add a global.json file with .net core version.

{
   "sdk": {
      "version": "2.2.402"
   }
}

From learn.microsoft.com:

global.json can be placed anywhere in the file hierarchy. The CLI searches upward from the project directory for the first global.json it finds. You control which projects a given global.json applies to by its place in the file system. The .NET CLI searches for a global.json file iteratively navigating the path upward from the current working directory. The first global.json file found specifies the version used. If that version is installed, that version is used. If the SDK specified in the global.json is not found, the .NET CLI rolls forward to the latest SDK installed. Roll-forward is the same as the default behavior, when no global.json file is found.

https://learn.microsoft.com/en-us/dotnet/core/versions/selection

Joinville answered 27/9, 2019 at 16:56 Comment(1)
It worked for me as well. though obvious, it requires the sdk version mentioned in global.json to be installed on machine as well.Nahuatl
G
1

This happened to me when I deployed code using Entity Framework Core with migrations, and there was mismatch between the state of the database and the migrations in the code.

Gressorial answered 30/10, 2019 at 11:59 Comment(0)
G
1

This happened to me first time publishing an Azure Web App. Here is how I solved it:

Browse the site using Kudo/FTP. In the root folder there is a LogFiles folder where you find eventlog.xml. In this file I could see that my web app had an SqlException when Entity Framework Core was trying to setup the database, which lead me to check the database permissions (which was the problem for me).

Gressorial answered 17/1, 2020 at 13:41 Comment(1)
Note it is also possible to view the event log in the Azure portal. You open the App Service, go to Diagnose and Solve Problems, then search for Application Events. https://mcmap.net/q/205591/-how-to-get-event-log-files-from-azure-app-service-without-cloud-explorerEldreda
L
1

This is what worked for me: - I ran the startup file of the project in the deployed (IIS) folder. Note that: this will not solve the problem but will inform you about what the problem is. In my case, the cause of the problem was a database migration that failed

Lalia answered 1/4, 2020 at 14:11 Comment(1)
Hi and welcome to Stack Overflow. Thank you for sharing a way in which you were able to diagnose and resolve the issue when you faced a very similar problem :)Dorothi
N
1

My .NET Core site was worked fine, but after a while, I got this error (HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure ...); I tried different methods. Finally I Add new web site in IIS (with other port), then the error was solved.

Nickelsen answered 15/8, 2020 at 8:44 Comment(0)
P
1

I got this issue in ASP.NET Core 2.2 project and its resolved for me just by Clean and Rebuild project.

enter image description here

Pastiness answered 16/12, 2020 at 20:30 Comment(0)
E
0

This error started appearing on our Dev server. I had been using this publish command which creates a "self-contained" folder of files for deployment.

dotnet publish -c release -r win7-x64 --output:bin/self_contained

My fix was to instead publish a "framework-dependent" deployment using the following command:

dotnet publish --output:bin/framework_dependent

The dev server did have a few versions of .NET Core installed (2.2.3 and 2.2.5) in this folder *C:\Program Files\dotnet\shared

I am still not clear on why the self contained publish does not work. You might think the self contained publish would be the more reliable method, but in my case it was not.

This .NET Core blog post was helpful.

Electrotherapy answered 17/5, 2019 at 14:28 Comment(1)
in your web,config, try changing <aspNetCore processPath="dotnet" into <aspNetCore processPath="C:\Program Files\dotnet\dotnet" as it's not necessarily always in the Path env variableStudnia
E
0

I got this same error while deploying .Net core app which was targeting .Net framework on Windows server. I checked event viewer on the server and turns out server didn't have .net 4.7.2 installed.

Installing it resolved issue for me.

Eudora answered 9/6, 2019 at 0:15 Comment(0)
T
0

Yet another scenario that caused this issue for me:

I am running the app pool identity with a service account and I had to run dotnet dev-certs https under this user to get rid of "System.InvalidOperationException: Unable to configure HTTPS endpoint." during startup.

Triclinic answered 21/8, 2019 at 16:55 Comment(0)
C
0

Same failture happent on project publish. The issue ralated with the latest Microsoft.AspNetCore.App package. Just downcast it from from 2.2.x to 2.2.0 or goto dotnet.microsoft.com/download/dotnet-core/2.2 and get newest dotnet-hosting installer

Colophony answered 16/9, 2019 at 10:25 Comment(0)
D
0

Be carefull publishing.

When i publish it to my PreProd envitoment this conf works well: Portable

But on my Prod enviroment that conf does not work. I had to choose the especificated one: win-x64

I dont know the reason about that. If someone know i'll gratefull to know!

Diplococcus answered 14/10, 2019 at 18:51 Comment(1)
I dont really know, but i'd have the same "explorer error" and that help me. I do not got the problem locally but yes after updating.Diplococcus
M
0

I was also getting the same issue. And when I looked at the Output window of my solution.

enter image description here

Then I was able to see a different error, which is "The target process exited without raising CoreCLR started event", to fix this I had to remove the Microsoft.AspNetCore.All from my Nuget Packages and install Microsoft.AspNetCore.App. I also had to install the correct .Net SDK from here. Once this is done, restarted my machine and open the solution, the error was gone. Hope it helps

Monocyclic answered 25/11, 2019 at 16:17 Comment(0)
H
0

If you are working with ASP.Net Core version 2.2 then in appsettings.json just comment the line -

"AllowedHosts": "*"

it resolves the issue. My application working fine.

Hutner answered 23/1, 2020 at 13:5 Comment(0)
N
0

This error can be happened because of many reasons. In my case it was an exception due to invalid format of appsettings.json . How I found out is by enabling stdout log in web.config.

Noonberg answered 11/3, 2020 at 5:32 Comment(0)
P
0

For me the issue was a missing appsettings.json

I select the appropriate appsettings.json file (appsettings.production.json or appsettings.development.json) based on an environment variable. Turns out the appsettings.json is required even if you dont use it.

Predecessor answered 8/5, 2020 at 4:26 Comment(0)
Q
0

My problem was with the web.config file after publishing. The processPath in the aspNetCore tag was missing the file extension. In my case it was .exe

Queen answered 16/6, 2020 at 18:8 Comment(0)
P
0

In my case EF Migrations thrown exception about blocking executing one of them because of a potential data loss. I had to look into custom app logs (most often Log folder) to find out that.

I guess the Error mentioned in the Question is due to problems during app start stage. And indeed the migrations are run during starting an app, so if they fail the app is not able to complete starting.

So in general when we get such Error we should focus on things that impact on starting logic of the app.

Professorship answered 18/6, 2020 at 10:6 Comment(0)
D
0

For me it was the web.config file, make sure you have it and to specify the paths correctly

<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\bin\Debug\netcoreapp2.0\logs\stdout">

Also the event viewer can be useful to detect app startup errors.

Ditmore answered 29/6, 2020 at 19:57 Comment(0)
M
0

This issue also comes up when a required value such as api endpoint that is required during the start of the project is missing in the app setting json. You might be parametizing it and not providing a value for the parameter. I get this in Azure devops

Marriott answered 5/8, 2020 at 12:18 Comment(0)
P
0

I set stdoutLogEnabled to true in Web.config. So in the log I discovered that the error was BadImageFormatException. Actually my web application was compiled in 32-bit, so I had to specify the 32-bit version of dotnet in Web.config:

<aspNetCore processPath="C:\Program Files (x86)\dotnet\dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
Ptarmigan answered 7/8, 2020 at 10:2 Comment(0)
H
0

Even I have faced the issue where post dotnet core 2.1 to 3.1 and .netstandard 1.1 to 2.1 with dotnet core 3.1 sdk.

When dotnet publish -c Release command was used files are in bin\Release\netcoreapp3.1 previously it was bin\Release\netcoreapp2.1\publish folder.

Not sure of the exact settings still we have publish folder but deploying from parent directory of publish folder did the trick

Houri answered 24/11, 2020 at 11:42 Comment(0)
R
0

For me, the problem was about creating the database from entity-framework, so i go to my SQL server, security, logins, and add new login for my IIS App Pool, and give the new login its server roles

Reticent answered 12/9, 2021 at 11:56 Comment(0)
F
0

In my case different target runtime are selected in different projects, when I selected it x64 which resolved my issue.

Foulard answered 25/7, 2023 at 10:28 Comment(0)
N
0

This is very simple issue that appear by mistake, For instance: If you update the depended referenced libraries and only copy the main project dll to iis hosting directory then this kind of issue appears. Copy the whole project published folder to wwwroot to be in safe side.

Nathalienathan answered 2/10, 2023 at 20:48 Comment(0)
E
-1

I followed below step and resolved. Best of luck:)

Step -1: Go to solution explorer < Right click < Property

Step-2:

Show your .Net Core framework or change as per your requirement but make sure all other existing DLL which is supported or you need to update.

Step-3: Download .NetCore package in your PC
See below link https://dotnet.microsoft.com/download

Encephalitis answered 12/11, 2020 at 9:53 Comment(0)
F
-3

My solution:

  • remove all projects with catalog
  • create new projects
  • copy all files but program.cs and startup.cs
  • manual copying from startup and program classes to new startup.cs and new program.cs

Works.

Firstling answered 20/2, 2019 at 17:44 Comment(1)
It may be a solution but it's a very "annoying" solution. I've never had to do this to fix an issue with a C# solution. Also, this error isn't usually related to the C# code itself but rather the server it is being hosted on.Discommode

© 2022 - 2024 — McMap. All rights reserved.