asp.net core 2.1 HTTP Error 502.5 - asp.net-core

When I am trying to run my solution I am getting In the browser:
HTTP Error 502.5 - Process Failure
Debugging stops almost immediately after it starts and there is no error message inside visual studio.
In the output window this is the only message:
The program '[30700] dotnet.exe' has exited with code -2147450730 (0x80008096).
The project was working fine, I just installed a nuget package and this started happening. I tried deleting it and removing the package cache but it still happens.
Event viewer shows error with IIS Express AspNetCore Module.
Application 'MACHINE/WEBROOT/APPHOST/PROJECTNAME' with physical root 'E:\path\ProjectName\' failed to start process with commandline 'e:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\web tools\projectsystem\VSIISExeLauncher.exe -argFile "C:\Users\username\AppData\Local\Temp\tmp49E1.tmp"', ErrorCode = '0x80004005 : 0.
I am a bit lost as there is no error to go on.
Any ideas?

Well! This is due to appropriate .NET Core SDK missing problem. Your project's package versions are higher than the SDK version installed on your machine.
Download the latest version v2.1.401 (at the time of that answer) from here: Download .NET Core SDK and install it.
Now restart your computer and run the project again.
Hope your problem will be solved!

Although it was already answered, I'll post here my solution for the same problem (HTTP Error 502.5 when starting my webapp on Asp.NET CORE 2.1, error code 0x80004005) that has a different reason, as reference of another possibility.
Short Answer:
If the name of the application has a space (character) on it, the current version of Visual Studio (15.8.9) has a bug, that doesn't include quotes to make it a literal string argument on the moment of execution (through commandline) on the web.config file, generated when publishing your webapp.
Example:
web.config generated by Visual Studio (version 15.8.9 - Date: 2018-Nov-05):
[...]
<aspNetCore processPath="dotnet" arguments=".\My Web App.dll" stdoutLogEnabled=... />
[...]
web.config with correct quotation:
[...]
<aspNetCore processPath="dotnet" arguments='".\My Web App.dll"' stdoutLogEnabled=... />
[...]
You can see on the attribute arguments on the second example, that I included (manually) single quotes, making it pass the full string ".\My Web App.dll" as the argument on the moment of execution.
Detailed Answer:
Every time I update my Visual Studio for a newer SDK (and using the most recent version of Asp.net Core in my application) it give me the Http Error 502.5, IF i do not update the runtime libraries on my server too. So, obviously the first thing that I did was update the runtime libraries on the server (which always solved this problem to me), but this time it didn't worked.
So, starting to troubleshoot, I just tried to start my webapp from the command line (prompt), and it started perfectly.
So, I knew that there was something wrong with the way my webapp was being started. The starting configuration (on asp.net core) is in the web.config file.
[...]
<aspNetCore processPath="dotnet" arguments=".\My Web App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
[...]
In Asp.net Core, the web application is started/executed from the commandline (prompt) on windows, by IIS (i'm strictly speaking of common scenario).
Till now, it always had a .exe file between the published files, that started the whole thing, and this was the file called by IIS Module through commandline.
Since Asp.net CORE 2.1 (and some minor update that i don't know exactly), there is no .exe file, and the PATH of Web App is passed by argument. So you have the command that is dotnet and a argument to this command that is specified as argument attribute, on the web.config file. (as shown in the example above)
Taking a look on my published web.config file, you can see the processPath and arguments attributes. In the previous test, I knew that dotnet was a recognized command, since I was able to start my webapp on windows command prompt. Then, looking carefully the arguments attribute, I saw that there was no (surrounding) quotation for the value, that contained space characters in it.
So in the startup of my webapp, instead the dotnet command receive the full path .\My Web App.dll, it was receiving 3 different arguments: .\My , Web , App.dll .
Since the value of the arguments attribute is passed through commandline, it has to have quotation when passed to the commandline, becoming a literal string.
So I mannualy added the necessary surrounding quotation on the arguments attribute value, in the web.config file, and my web app started to work perfectly!
To see the example of the bug, and how to correct it, just take a look on the "Short Answer" examples.
Other useful information (for Asp.net Core 2.0 and up, with Windows / IIS):
If you had a web application that was working, and is not anymore, giving the error 502.5:
It's probably a versioning problem of the runtime libraries. Your webapp is asking for newer asp.net core libraries, and your server doesn't have them yet.
Just update the runtime libraries on your server, and it should solve the problem. Download it from Microsoft (for the current version which is Asp.net Core 2.1, you can download from this link: https://www.microsoft.com/net/download/dotnet-core/2.1).
How to start your webapp manually, for better troubleshooting:
Open the windows command prompt, and try to execute the command dotnet. If it's not recognized, than you have to install (or repair) the asp.net core module and dependencies (google is your friend. Just search how to install asp.net core). Alternatively, you can check the Asp.net Core runtime libraries version with the command dotnet --version.
Once the dotnet command is recognized, you can start your webapp manually.
Navigate to the folder where is your webapp files (usually will be in inetpub, wwwroot, etc..). Then, locate the .dll file that is your application's assembly. Usually, it will have the name of your application (pretty easy, right!?). Then, execute it with the command dotnet ".\My Web App.dll".
Example:
If there is a error, you will see some useful information on the prompt window. If the webapp starts correctly, then it's some issue with the startup configuration, probably web.config file.
Another method to see more detailed information on asp.net core failure:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore-2.1#application-event-log
Access the Application Event Log:
Open the Start menu, search for Event Viewer, and then select the Event Viewer app.
In Event Viewer, open the Windows Logs node.
Select Application to open the Application Event Log.
Search for errors associated with the failing app. Errors have a value of IIS AspNetCore Module or IIS Express AspNetCore Module in the
Source column.
Details of my issue:
When executing requests, the error presented was: HTTP Error 502.5 - Process Failure.
Looking on the Events Viewer (Windows Server), the information was: "Application ' ... My Web App' with physical root 'C:\ ... \ ... \' failed to start process with commandline 'dotnet .\My Web App.dll', ErrorCode = '0x80004005 : 1."
So my error code was: 0x80004005 , and the subcode was 1.
Hope it helps somebody :)

Related

Launch IIS Express to run ASP.NET Core Apps

I wish to run my ASP.NET Core App by launching it from IIS Express using command line.
I stumbled across this article which says
So in fact Visual Studio silently adds the two environment variables
when launching IIS Express, so that ASP.NET Core related bits can be
injected.
LAUNCHER_ARGS: -debug -p “C:\Program Files\dotnet\dotnet.exe” -a “exec
\”C:\Users\lextm\documents\visual studio
2017\Projects\WebApplication2\WebApplication2\bin\Debug\netcoreapp1.0\WebApplication2.dll\””
-pidFile “C:\Users\lextm\AppData\Local\Temp\2\tmpFD6D.tmp” -wd “C:\Users\lextm\documents\visual studio
2017\Projects\WebApplication2\WebApplication2”
The tmp file in -pidFile “C:\Users\lextm\AppData\Local\Temp\2\tmpFD6D.tmp” can always change. How do I add LAUNCHER_ARGS as environment variable which will make it work even if the tmp file changes?
Let me know if there is any easier way to launch IIS Express to run ASP.NET Core Apps with command line or powershell scripts.
You are looking for [System.IO.Path]::GetTempFileName() method. It creates empty temp file on file system and returns its unique name.
I'm currently using the following PowerShell script to run my .NET Core 2.0 App:
$env:LAUNCHER_ARGS = "-p ""<path to dotnet.exe>"" -a ""exec \""<path to webapp main dll>\"""" -pidFile $([System.IO.Path]::GetTempFileName()) -wd ""<path to webapp root folder>"" -pr <project name>"
$env:LAUNCHER_PATH = "<path to VSIISExeLauncher.exe>"
& "<path to iisexpress.exe>" /config:"<path to applicationhost.config>" /site:"<webapp name>"
Placeholders (text within angle brackets) have to be filled with the corresponding values. You can find them out by running your project from Visual Studio and inspecting environment variables of iisexpress.exe process using Process Explorer as shown above in the link you provided.
In .NET Core 3 the solution to this problem has changed. Follow these steps.
1) The environment variables should now be:
LAUNCHER_ARGS=exec "C:\YourWebApiProject\bin\Debug\netcoreapp3.1\YourWebApiProject.dll"
LAUNCHER_PATH=C:\Program Files\dotnet\dotnet.exe
Change the first path to your dll path and ensure the .NET version in the path is correct. Note that there is no longer a need to create a temp file.
2) Ensure that both modules AspNetCoreModule and AspNetCoreModuleV2 are registered in the file .vs\{your solution name}\config\applicationhost.config as follows:
Under <system.webServer> <globalModules> add:
<add name="AspNetCoreModule" image="%IIS_BIN%\aspnetcore.dll" />
<add name="AspNetCoreModuleV2" image="%IIS_BIN%\Asp.Net Core Module\V2\aspnetcorev2.dll" />
Under <sectionGroup name="system.webServer"> add:
<section name="aspNetCore" overrideModeDefault="Allow" />
Under <location path="" overrideMode="Allow"> <system.webServer> <modules> add:
<add name="AspNetCoreModule" lockItem="true" />
<add name="AspNetCoreModuleV2" lockItem="true" />
It's also a good idea to make this change to the templates for this file which are located at %PROGRAMFILES%\IIS Express\config\templates\PersonalWebServer\applicationhost.config and %PROGRAMFILES(x86)%\IIS Express\config\templates\PersonalWebServer\applicationhost.config so that new VS solutions you create automatically get these changes to their configs. (Credit to this post)
3) Be mindful of whether you're using 32 or 64 bit IIS Express. (If you're on a 64 bit machine then 32 bit IIS Express = C:\Program Files (x86)\IIS Express, 64 bit = C:\Program Files\IIS Express) In my case, 32 bit had worked fine previously but after migrating to .NET Core 3 I had to use 64 bit or else the above modules wouldn't load.
I needed to run multiple .Net Core API endpoints at a time easily without popping open Visual Studio for each and every one of them. I ended up using answers here to build the following:
iisaspnet.bat:
#echo off
:: Args are like:
:: MobileApi
:: C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src\HCPMobileApi
:: MobileApi\bin\Debug\netcoreapp2.2\MobileApi.dll
:: .vs\MobileApp\config\applicationhost.config
setlocal
set PATH=%PATH%;C:\Program Files\IIS Express
set LAUNCHER_ARGS=exec %2\%3
set LAUNCHER_PATH=C:\Program Files\dotnet\dotnet.exe
iisexpress /site:%1 /config:"%2\%4"
:: Comment out line below to check for errors
exit
The first arg is the name of the Project - the name in Visual Studio (in some scenarios people go rogue and name their Project file one thing and the Project itself another thing - you want the Project name, not the file name, in this scenario).
The second arg is the root folder for third and fourth args.
The third arg is where to find the compiled Project DLL
The fourth arg is where to find the applicationhost.config that explains how to launch the site. As you'll see below, this is generally found in your .vs folder, but, where this exists can get a little crazy depending on how creative people get with organizing their Solution and Project folders. Generally the .vs folder is going to sit in the same folder as the .sln file, so it may be far from the Project folder/files.
This will be less helpful, but here's the batch file that kicks off the IIS Express windows, so you can see iisaspnet.bat in use:
start iisaspnet.bat MobileApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src\HCPMobileApi MobileApi\bin\Debug\netcoreapp2.2\MobileApi.dll .vs\MobileApp\config\applicationhost.config
start iisaspnet.bat HCP.MasterDataApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src MasterData\Api\HCP.MasterDataApi\bin\Debug\netcoreapp2.2\HCP.MasterDataApi.dll Solutions\.vs\MasterData\config\applicationhost.config
start iisaspnet.bat HCP.SecurityApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src Security\Api\HCP.SecurityApi\bin\Debug\netcoreapp2.2\HCP.SecurityApi.dll Solutions\.vs\Security\config\applicationhost.config
start iisaspnet.bat HCP.BillingApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src Billing\Api\HCP.BillingApi\bin\Debug\netcoreapp2.2\HCP.BillingApi.dll Solutions\.vs\Billing\config\applicationhost.config
start iisaspnet.bat HCP.ClientApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src Client\Api\HCP.ClientApi\bin\Debug\netcoreapp2.2\HCP.ClientApi.dll Solutions\.vs\Client\config\applicationhost.config
start iisaspnet.bat HCP.EmployeeApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src Employee\Api\HCP.EmployeeApi\bin\Debug\netcoreapp2.2\HCP.EmployeeApi.dll Solutions\.vs\Employee\config\applicationhost.config
The way the parameters work could likely be far simpler if the way the Projects, Solutions, etc were stored and named was more consistent, but, this is an existing set of Solutions I had no control over with scattered naming etc, and, the chaos above may be more helpful anyway for understanding how to call these commands.
The result is that running one command kicks off 6 IIS Express command windows for me, requests get logged to each of their windows, and I just type Q in each window to kill them.

vb.net CLR/SHIM error: This application could not be started. --> Unable to find a version of the runtime to use

Getting an unexpected, "This application cannot be started" popup error that is suggesting SHIM_NOVERSION_FOUND error in .NET CLR. Here's what's going on...
I have two vb.net applications:
1- MyApp.exe -- Windows Forms App
2- Launcher.exe -- Windows Service
Both are .NET framework 4.5 applications, and Launcher.exe is embedded inside MyApp.exe. Both are configured for AnyCPU, and neither use an app.config file. The reason being that the delivery tool can only deliver a single file, so I can't include any extras. The executable must be self-contained, and you can't embed an app.config file.
The execution runs in the following layers:
Layer 1: Delivery tool
Native C++ application
Elevated, running as Local System Account
Layer 2: MyApp.exe
.NET 4.5 application
Elevated, running as Local System Account
It runs fine, and installs Launcher.exe as a new Windows Service.
Layer 3: Launcher.exe
.NET 4.5 Windows Service
Elevated, running as Local System Account
Uses Windows API calls to enable the following privileges: SE_INCREASE_QUOTA_NAME, SE_ASSIGNPRIMARYTOKEN_NAME, SE_TCB_NAME
In summary, it uses elevated privileges to search for Explorer.exe processes, open them, duplicate the user's security token, and call the CreateProcessAsUser() API, using the user's token, in order to launch a second copy of MyApp.exe, running on the user's desktop.
Layer 4: MyApp.exe
.NET 4.5 application
Fails to launch with popup error --> This application could not be started.
It's A COPY of MyApp.exe, same as layer 2.
I've enabled .NET CLR debugging to compare the loading of MyApp.exe at layers 2 and 4:
Layer 2:
6172,1589.119,Parsing config file: C:...\MyApp.exe.config
6172,1589.119,Config File (Open). Result:80070002
6172,1589.119,UseLegacyV2RuntimeActivationPolicy is set to 0
6172,1589.119,LegacyFunctionCall: GetFileVersion. Filename: C:...\MyApp.exe
6172,1589.119,LegacyFunctionCall: GetFileVersion. Filename: C:...\MyApp.exe
6172,1589.119,C:...\MyApp.exe was built with version: v4.0.30319
6172,1589.166,Decided on runtime: v4.0.30319
Layer 4:
6552,1594.704,Parsing config file: C:\windows\TEMP\MyApp.exe.config
6552,1594.704,Config File (Open). Result:80070002
6552,1594.704,UseLegacyV2RuntimeActivationPolicy is set to 0
6552,1594.704,LegacyFunctionCall: GetFileVersion. Filename: C:\windows\TEMP\MyApp.exe
6552,1594.704,ERROR: Unable to find a version of the runtime to use.
6552,1594.704,SEM_FAILCRITICALERRORS is set to 5
6552,1688.055,FunctionCall: RealDllMain. Reason: 0
6552,1688.055,FunctionCall: OnShimDllMainCalled. Reason: 0
Random facts:
This doesn't happen on all computers targeted.
Disabling the antivirus doesn't resolve on affected systems.
On some computers, the error only happens once, and subsequent executions do not reproduce the popup error.
Looking for any help in understanding or debugging WHY .NET CLR is unable to determine the runtime version to use, when that very same application has already launched successfully!
I had the same issue with a Windows service running as LocalSystem and a WPF application that I was trying to run using CreateProcessAsUser by duplicating the user token pertaining to the active session (WTSQueryUserToken). When running the .exe manually it worked, but when the service was trying to create the process I kept receiving "This application could not be started". I also got the same CLR logs as you with "ERROR: Unable to find a version of the runtime to use.".
These are the things I've done:
Set OnlyUseLatestCLR registry value to 1
Use UNC paths for mapped drives (I am running inside a Windows VM and for some reason the system could not find the path for the config file after loading the app)
Check firstly if the path you are passing to CreateProcessAsUser is correct.

trouble publishing website TFS 2013

I have a TFS 2013 build that I'm trying to get to publish to a folder on the build server. I've installed WebDeploy, but I always get the error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets (4274): Web deployment task failed. (Could not connect to the remote computer ("localhost"). On the remote computer, make sure that Web Deploy is installed and that the required process ("Web Management Service") is started. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_DESTINATION_NOT_REACHABLE.)
I've set up a website on the build server and that's where I'm trying to publish the website. Actually I don't even care about publishing it per se - I just need my build output to go to a folder locally automatically. Right now we have to manually open the solution and choose Publish... to get the output that subsequent InstallShield builds need for input. Here are my MSBuild arguments. Does anyone have any idea what could be missing?
/p:SrcDir=C:\Builds\TFS\WebApps\Src
/p:RevKeyname=WebAppsRevNr
/p:DeployOnBuild=true
/p:DeployTarget=MsDeployPublish
/p:MSDeployServiceURL=https://127.0.0.1:8172/msdeploy.axd
/p:CreatePackageOnPublish=True
/p:DeployIisAppPath="WebApp"
/p:MsDeployPublishMethod=WMSVC
/p:AllowUntrustedCertificate=True
/p:AutoParameterizationWebConfigConnectionStrings=False
/p:Authtype=NTLM /p:username=""
I've checked both net start wmsvc and net start msdepsvc and both are running. Any ideas?
Thanks!
UPDATE
I've tried everything that Andy suggested and now when I run this from the command line I get this bizarre error message:
"C:\Workspace\VS2013\WebApps\Main\Src\webapps.sln" (default target) (1) ->
"C:\Workspace\VS2013\WebApps\Main\Src\CoreWebApps\CoreWebApps.csproj"
(default
target) (7) ->
(AutoParameterizationWebConfigConnectionStringsCore target) ->
C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web
.Publishing.targets(2295,5): error : Could not open Source file: Could not
find
a part of the path
'C:\Workspace\VS2013\WebApps\Main\Src\CoreWebApps\Areas\Adm
in\Views\Web.config;Areas\Admin\Views\Web.config'.
[C:\Workspace\VS2013\WebApps
\Main\Src\CoreWebApps\CoreWebApps.csproj]
Any idea why it's looking for Web.config;Areas\Admin\Views\Web.config'.? That makes no sense.
Please try below items to narrow down the issue:
Try to use IP or Machine Name instead of "localhost"
Logon your build agent machine, then manually execute the same
MSBuild command within the same arguments(which you provided in build
definition) to build and deploy your solution, then check result. You
need to ensure you can manually run the same MSBuild command within
deploy argument to build and deploy your solution successfully from
build agent machine. Then use the same deploy arguments in TFS Build
definition.
Double check Web Deploy settings to make sure that the name of the
website is exactly that of what's in IIS.
Install Web Management Tools before Web
Deploy : Install the Web Management Services (Roles -> Web Server >
Management Tools > Management Services). Then uninstall Web Deploy, and then install Web Deploy again.
You can also reference this thread for your troubleshooting.
Update:
For the issue "Could not open Source file: Could not find a part of the path" you can reference below similar articles for the troubleshooting.
https://social.msdn.microsoft.com/Forums/en-US/8f959964-c951-4f9a-8486-8283a925c9f6/build-error-could-not-open-source-file-though-i-know-it-exists?forum=windowsazurewebsitespreview
https://our.umbraco.org/forum/getting-started/installing-umbraco/60222-Umbraco-721-Build-fails-after-deploy-to-Azure-WebSite (See the last two answers)

MSBuild SonarQube Runner v1.0 returns with code 1 after "Generating the FxCop ruleset"

I'm trying out SonarQube using the new MSBuild SonarQube Runner v1.0. If I install a fresh SonarQube server locally, the following command works fine, and I can build my solution directly afterward, call the 'end' command, and have the results published in SonarQube:
MSBuild.SonarQube.Runner.exe begin /key:TestKey /name:TestName /version:1.0.0.0
However, if I run this against an existing SonarQube server that exists on the internal network, it always returns with exit code 1:
15:32:40 Creating config and output folders...
15:32:40 Creating directory: c:\Test\MSBuild.SonarQube.Runner-1.0.itsonar\.sonarqube\conf
15:32:40 Creating directory: c:\Test\MSBuild.SonarQube.Runner-1.0.itsonar\.sonarqube\out
15:32:41 Generating the FxCop ruleset: c:\Test\MSBuild.SonarQube.Runner-1.0.itsonar\.sonarqube\conf\SonarQubeFxCop-cs.ruleset
Process returned exit code 1
It seems to download a lot of the dependencies into /.sonarqube, so communication with the server isn't an issue
Things I've tried:
checked the access.log, server.log and event logs
upgraded the existing server to v5.1.2 (clean install using the guide)
upgraded the sonar-csharp-plugin to v4.1
right-clicked all .jar files on the server and ensured they are unblocked
tried the runner directly on the server
(ongoing) tried debugging the source code (happening somewhere in the pre-process step: success comes back as true, but the error code is 1)
disabled UAC on the server an rebooted
re-installed JRE on both server and client, ensure JAVA_HOME in both PATH and registry are set correctly
Any help or pointers greatly accepted. I've been stuck on this for 2 days and can't think of anything else to try except continue trawling through source code. Thank you.
This is a tricky one! Looking at the code, I see only one path that can yield this output:
It fails while generating the FxCop ruleset for C#, as the VB.NET FxCop ruleset message is not logged - see TeamBuildPreProcessor.cs#L149 and TeamBuildPreProcessor.cs#L185
The GenerateFxCopRuleset() call for C# threw a WebException, leading to the call of Utilities.HandleHostUrlWebException() - which has to return true for the exception to be silently swallowed - see Utilities.cs#L153
The only path returning true without logging any message is if a HttpStatusCode.NotFound was received - see Utilities.cs#L158
The control flow goes back to FetchArgumentsAndRulesets(), which returns false, then goes back to Execute() which returns false as well - see TeamBuildPreProcessor.cs#L106
The MSBuild SonarQube Runner "begin" phase (called "preprocessor" in the code) fails - see Program.cs#L42
So, at some point, some SonarQube web service required for the C# FxCop ruleset generation is return a HTTP 404 error.
Could you monitor your network traffic and listen for the failing HTTP call? [I will keep on updating this answer afterwards]
EDIT: Indeed the error is caused by the quality profile name containing special characters. Such characters are currently badly URL-escaped, which leads to a 404.
I've created the following ticket to fix this issue in the upcoming release: http://jira.sonarsource.com/browse/SONARMSBRU-125

Problems using CruiseControl.Net API : project not found

I am trying to retrieve Build Projects related information from my CruiseControl server through command line using cccmd.exe and passing the url and project name as command line arguments. The problem is when I am trying to use API's exposed by Cruise Control Service like
client.GetArtifactDirectory(project.Name);
client.GetLatestBuildName(project.Name);
I am getting the exception "The project does not exists on the CCNet Server" for my local CCNet Server.
For my production build server, I am getting the exception "Key cannot be null".
Finally found the solution, had to copy the folders and foldername.state files that are created during project build process to the directory from where ccservice.exe was running.