net 4.7 service install upgrade - c#

I inherited a .net service project which does not support TLS 1.2, project was upgraded to .net 4.7. Previous .exe file was replaced with the new 4.7exe and the service was restarted. Service cannot be started due to error "1064:An exception occurred in the service when handling the control request"
Do I have to use installutil.exe MyNewService.exe to install a service?
The installutil.exe is located in C:\Windows\Microsoft.NET\Framework\v4.0.30319, would this support .net 4.7 or do I need to download and install .NET Framework 4.7 offline installer for Windows?
Thanks for any tips or suggestions, I am not familiar with .net services!

Ensure you include all output files from the build, including the app.config file. There might be assembly redirects there which are required by 4.7.
Is the correct .NET Framework version installed on the server you're running the service on?
If that doesn't help, try running the application from command prompt, if your application supports it (I recommend it should). If that works, the service user running the service might be missing some permissions.
Add logging. As minimum, add try-catch statements in your service entry points and log any exceptions to a file. You can also add a handler to AppDomain.UnhandledException which will -usually- be called before the application crashes.

Related

Hosting a WCF service in NetStandard 2.0 Class Library

I recently migrated a dotnet framework v4.7.2 WCF service with the upgrade-assisstant tool to NetStandard 2.0. the project successfully migrated and compiled, BUT I couldnt start the service either from visual studio nor dotnet cli.
the Error I get from dotnet cli tool is :
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found.
AND the error I get trying to start the service from visual studio, solution explorer -> right click on wcf project -> debug -> start new instance is:
A project with an output type of class library couldnt start directly.
P.S when the WCF service was still dotnet framework v4.7.2 I could easily start the service doing the above mentioned procedure in visual studio.
As I know .net 4.7.2 is the lowest real version that supports .netstandard 2.0 In this link.
You can back it up and upgrade to 4.7.2 to try it out.
WCF server APIs are not supported on .NET Standard or .NET Core/.NET 5+, so there's no good way to migrate such an app forward.
Upgrade Assistant tries to figure out whether a project should upgrade to a library or an exe based on the previous project type. For this project, Upgrade Assistant guessed it was a library since there was no traditional main method and it wasn't a web app or some other project type that the tool understood as executable. Regardless of whether it upgraded it as a .NET Standard library or as a .NET 5 exe, though, it wouldn't work because WCF server APIs are only supported on .NET Framework.
It might be nice if Upgrade Assistant alerted you to that early in the process so you knew upgrading wouldn't work for this type of project. I thought it had a feature like that, but it must have missed for this specific project. You could provide feedback on the tool's GitHub page (https://github.com/dotnet/upgrade-assistant/issues).
As far as how you can actually upgrade WCF server stuff, you'll need to re-architect using a different technology like ASP.NET Core, gRPC, or CoreWCF.

In sever restart required after installing .NET Core Runtime and SDK?

In server already other app published so when I published my asp.net core app getting error so I installed NET Core Runtime and SDK but not restart server due to other app running but after installing runtime and SDK issue not solved so confused restart required or not?
No, generally it should not: https://social.msdn.microsoft.com/Forums/vstudio/en-US/ecd4223d-7099-4e38-a2d0-27099e7c7dda/net-core-30-after-installation-does-it-require-reboot?forum=vsx
In general, we do not need to restart PC and if you install the official version,you do not need to do any restart. If you install the preview of .Net Core 3.0, you should check this option(Tools--Options-->Environment-->Preview Features-->use previews of the .net core sdk(require restart)) and then restart VS.
There is a mention here: Restart needed after installing .NET Core Runtime and SDK? about windows services needing at least a log off, but in general there should be no need.
The installer itself will tell you if a restart is needed. Restart is needed only if some files are currently in use. If you close the applications that use those files, you won't have to restart.
The installer will even tell you which applications lock needed files and even offer to close them during installation. A restart is only needed if you can't stop those applications during installation.

HTTP Error 500.31 - Failed to load ASP.NET Core runtime

I'm having issues deploying .NET Core applications to IIS on a Windows 10 machine.
When I deploy to IIS and navigate to the site I recieve the message:
"HTTP Error 500.31 - Failed to load ASP.NET Core runtime
Common solutions to this issue:
The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.
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: https://go.microsoft.com/fwlink/?LinkID=2028526
In my event viewer, every call to the page generates 3 error messages.
Unable to locate application dependencies. Ensure that the versions of Microsoft.NetCore.App and Microsoft.AspNetCore.App targeted by the application are installed.
Could not find 'aspnetcorev2_inprocess.dll'. Exception message:
Failed to start application '/LM/W3SVC/4/ROOT', ErrorCode '0x8000ffff'.
On these alone, I'd go down the rabbit hole of thinking there's some issue in the build of the project or perhaps my installation of some .NET Core package except:
I have two other .NET Core 3.1 sites running at different ports. In fact, if I copy the files from the directory of a working site, to the directory of a non-working site they will not run through IIS. If I copy files from the directory of a non-working site, to a working site, those files will run through IIS.
If I click on the executable for any of the sites and navigate to the specified localhost, they open up in a web browser just fine.
I can run all manner of framework-dependent and Self-Contained .Net Core 3.1 and .Net Core 5.0 console apps anywhere on the same system.
The two sites that do work, showed the same error message the first time I went to publish. I tried adjusting settings, reinstalling runtimes and the like but failed to isolate anything that caused them to start running a few hours after the first attempt at deployment.
There is no visibile difference in settings in the Application Pool or the sites themselves between the sites that work and the sites that don't.
I think there must be some issue with how I've configured IIS, the sites, or the application pools, but as best I can tell there isn't any difference. If anyone has encountered this, I'm all ears for suggestions.
In my case, the target machine was missing the ASP.NET Core runtime itself.
Issue is resolved after installing the Hosting Bundle from
.Net Core 3.1
Similar to Alex Monkey's answer, I was missing the hosting bundle.
To be more specific, my problem was that I accidentally installed just the runtime instead of the hosting bundle. I assumed the "x64" link in the picture below would download an x64 version of the bundle, but it does not.
You need to click the words "Hosting Bundle" to get the correct installer:
Get the hosting bundle for any version of .NET here.
I was getting the same error messages for a new .NET Core 3.1 framework-dependent web app on an IIS server which was already hosting other .NET Core 3.1 framework-dependent web apps with no problem. The messages in Event Viewer were slightly different; but also very hard to find - sometimes I couldn't see any events which seemed to relate.
If I converted the site to stand-alone "win-x86", it worked; but stand-alone "win-x64" didn't work.
After days of...
Reading the information on the linked Microsoft URL in the error message,
running the site from the command line (no problem),
checking dotnet --info on the IIS server,
checking dotnet --info on the build server,
staring at JSON config files, project files, build settings, publish settings and IIS settings
...this turned out to be an AppPool setting.
In the AppPool's Advanced Settings, there is an "Enable 32-Bit Applications" setting, which IIS considers the default to be False; but on mine was True. Toggling this setting caused the site to work and fail, when False and True, respectively.
It had been set to True on my site because we use octopusdeploy to deploy our site, and the "IIS AppPool – Create" step has an option relating to this setting; but in Octopus, the default value is True, so this needed turning off.
Using the tool suggested (and created) by #LexLi I was able to determine the issue was caused by the application pool not having permissions to the site folder. Giving it permissions fixed the issue. This was not clear from the error messages. Answered here in case anyone else experiences the same error message.
My fix was:
in the error it usually says which version of runtime it tried to load, and which versions it found instead.
running dotnet --info gives the list of installed .NET runtimes:
mine was missing 5.0.0.
so I went to https://dotnet.microsoft.com/en-us/download/dotnet/5.0
and expanded the 5.0.0 and installed the version I needed. solution builds fine now.
Even though 99% of the time, it is probably due to a missing or incorrect runtime version of .NET/.NET Core, here is something you can try:
Check that the arguments property of the aspNetCore XML element in your web.config file is pointing to the correct project.dll file (and that the file exists).
In my case, I had a perfectly setup web.config file for one project and tended to just copy that to new projects.
Occasionally, I would forget to change the arguments value in that area and it yielded the error that makes you think its a runtime issue with your dotnet version.
What helped me get there is that it worked with a blank .NET6 project in my shared hosting plan so I knew it was not a missing .NET6 runtime issue.
<aspNetCore
processPath="dotnet"
arguments=".\YourProject.dll"
stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" hostingModel="inprocess"
>
<environmentVariables>
<environmentVariable
name="ASPNETCORE_ENVIRONMENT"
value="Development"
/>
</environmentVariables>
</aspNetCore>
HERE: arguments=".\YourProject.dll"
I had the same problem...
my solution is quite simple and sort of embarrassing at the same time :)
I thought asp.net core host bundles are downward compatible.
Solution: my application was configured with 3.1. as target framework but I had installed the 5.0.9 hosting bundle on the iis.
After I installed the right version of the hosting bundle, the 3.1. version, it worked!
I resolved this error by changing Deployment Mode from Framework Dependent to Self Contained during the publishing process. Not sure how this change fixed that, but it works for me. I use .NET 5.
For me, I had to install both .NET 5 and .NET Core 3.1. Some folks here were suggesting to download 3.1 (my app is targeting 3.1) but when I go to the Microsoft site it "recommends" the latest which at the time of this post is 5.0 (https://dotnet.microsoft.com/download/dotnet/5.0).
Well, 5.0 alone causes the (HTTP Error 500.31 - Failed to load ASP.NET Core runtime) issue.
I was finally able to fix it AFTER I installed 3.1 as well https://dotnet.microsoft.com/download/dotnet-core/3.1.
I got this error because my App needs "Microsoft.WindowsDesktop.App", I don't know why.
Check the file: MyAppTest.runtimeconfig.json
Show config json file
but sure, you need to install "Hosting Bundle" (the right version)
I had this issue on production after few days of deployment. Suddenly stopped working with the error (HTTP Error 500.31 - Failed to load ASP.NET Core runtime). In my case, I just repaired the installed version and it worked.
I had same issue on production after deployment. Please check all of the dll are deployed on production server. In my case one of the dll was missing. I just upload that dll and it worked.
In my case the problem was the IIS server had the required version Microsoft.AspNetCore.App 5.0 and when I ran the dotnet cmd I noticed that it only had Microsoft.AspNetCore.App 6.0 installed.
I found the required version of Microsoft.AspNetCore.App on the IIS server by consulting the deps.json file.
https://social.msdn.microsoft.com/Forums/en-US/20b5e111-11bd-4a9a-85fe-0522112ce84d/need-help-with-resolving-http-error-50031-on-iis?forum=aspdotnetcore
After a long agonizing search my problem was in my .runtimeconfig.json file
For some reason it had "tfm": "net3.1" and "version : "3.1.0". My fix.
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.AspNetCore.App",
"version": "6.0.2"
},
Had this error when i first deployed my new .Net Core 6 app to the IIS. Then I found out I need to switch from framwerok-dependent mode to self-contained, which containes the target .NET runtime.
The problem was gone.
I just ran into this issue and my fix is similar to the answer above by #Janatbek Orozaly.
I'm now moving a site to another server so in the process of setting up the new server to host the website I came across this issue. I like another user above thought that the latest supported versions of .Net6 or .Net7 where downward compatible, which it is not having following this thread.
Would also like to point out that even the latest version may not be compatible with the targeted framework as well. So I initially tried using 5.0.17 (latest version of .NET5) and was still having the same issue. I was able to resolve this issue by installing the 5.0.4 version. At the time, the website was built using NET 5.0 framework.
Sometimes it helps recycling the Application Pool.

ClickOnce Deployment .Net Framework 4.6.1 installation error

I have a clickonce application being tested on a virtual machine. This virtual machine is empty and my application requires .Net Framework 4.6.1 on the machine. Now, my application is able to install .Net 4.6.1 but I'm having a weird behavior after install. I'm receiving this message when the application is being open after the installation of .Net 4.6.1.
I added 4.6.1 on my prerequisite by following this guide. How to Create .Net Framework Prerequisites Entry in Microsoft Visual Studio 2015
Here's the message
When I try to run the setup again, the setup process goes through then it launches my application. It seems the setup cannot detect the framework installed right after it install it. Or something went wrong somewhere during the installation. Is there a way to handle this? Any suggestion will be appreciated. Thanks!
The error message says that your application requires CLR 4.0.xxxx. If you specify .NET 4.0 as requirement too ? Maybe you are trying to execute something developped with .NET 4.0 anyway. This could help you :
Backward compatibility and the .NET Framework 4.5 :
The .NET Framework 4.5 and its point releases are backward-compatible with apps that were built with earlier versions of the .NET Framework.In other words, apps and components built with previous versions will work without modification on the .NET Framework 4.5.However, by default, apps run on the version of the common language runtime for which they were developed, so you may have to provide a configuration file to enable your app to run on the .NET Framework 4.5.For more information, see the Version compatibility for apps section earlier in this article.
source

Debugging .Net web api

I built a .net web app using visual studio. I tested it in visual studio and it seemed to work fine. After publishing it locally and copying to my remote web server it seems to keep crashing the application pool and I'm not sure how to debug it.
How I published it: I published it locally and copied all the files to: wwwroot/ss/ on the remote server. After that, I installed the folder as an application in IIS. Because it was built using version .net 4.5 framework but I only had .net 4.0 application pools I did:
appcmd set apppool /apppool.name: api /managedRuntimeVersion:4.5
Now, anytime I go to the application using my url: mywebsite.com/ss/api/controller/param, I get a 503 service unavailable.
When I check the application pool after I go to that URL, the app pool has been shut down. I tried using try/catches, but it doesn't seem to help. All I see in the log file is:
2015-03-09 01:01:39 remoteIP 14132 siteIP 80 HTTP/1.1 GET /ss/api/controller/param 503 4 AppOffline api
What's the best way to debug this? Can I use a remote debugger? Is there any folder besides C:\Windows\System32\LogFiles\HTTPERR or logs/LogFiles folder in the site root where I can find more information about why it crashed?
EDIT:
If it is at all useful, I see in the event log:
I see several warnings:
A process serving application pool 'api' terminated unexpectedly. The process id was '2724'. The process exit code was '0xfffffffe'.
followed by:
Application pool 'api' is being automatically disabled due to a series of failures in the process(es) serving that application pool.
There is no such thing as the .net 4.5 run time. Set it back to .net 4.0
appcmd set apppool /apppool.name: api /managedRuntimeVersion:4.0
Fun fact.
There are only 3 .net runtimes as of 2015-03-09
.net runtime 1.0
.net runtime 2.0
.net runtime 4.0
These runtimes allow you to run the following (ignoring the various SP)
.net runtime 1.0
.net framework 1.0
.net runtime 2.0
.net framework 2.0
.net framework 3.0
.net framework 3.5
.net runtime 4.0
.net framework 4.0
.net framework 4.5
.net framework 4.5.1
.net framework 4.5.2

Categories

Resources