I am developing an app to install & run as a Windows service. It's still buggy and stopped unexpectedly (leaving nothing in the Windows Event log either) and when I tried to start it up again I got the error
Windows could not start the {name of service} service on Local Computer.
Error 1067: The process terminated unexpectedly.
I restarted the computer (Server 2008 R2; a virtual machine, in case that makes a difference), no help. Uninstalled and reinstalled my service, and still get that error!
Something on the machine needs cleared out / refreshed so that it will attempt to start the service again. I don't want to rebuild the whole virtual machine but I'm out of ideas.
UPDATE
I forgot to mention that this Windows service -- exact same code & install -- is running on 3 other machines without the above error. Putting in that debugger in OnStart() still sounds like the way to go though.
If you have access to the code, you can add a method Debugger.Break at the first line of the OnStart method.
Once you "break" into the application investigate where the exception is thrown.
You can attach the debugger to a running service. Details at Debug Windows Service Applications.
It's fortunate that you can replicate the problem easily. You can install the .NET Studio with code to debug your problem.
Another technique is to make the Service into a regular app. You know that the suspect code is during Startup. So simply create the app with code in the Startup function, and start debugging from there.
Good luck,
Tommy Kwee
Related
I currently found an issue that one of my projects, which is a windows service, stops immediately after it starts. It was not like this before.
Worse still, I am unable to attach the service to Visual Studio since it stopped immediately after it started.
My system is Windows server 2012 R2 and Visual Studio is 2013.
Is there any way for me to debug the service?
You can start the service directly under debugger. To achieve this you can either modify the service start command (sc config binPath=) or you can use GFlags to alter the service image to start under debugger. In both cases your debugger will be in the background and you'll need to then remote into it.
But usually you can solve the issue from dumps, if any. Often simply starting the service executable from the same account as the service will reveal the issue.
Finaly lets not forget the power of printf. Add logging and isolate the issue from the logs. Your service should be doing this anyway.
I have just found an answer in MSDN.
https://msdn.microsoft.com/en-us/library/cktt23yw.aspx
Add the following code:
System.Diagnostics.Debugger.Launch();
At the very beginning of OnStart method. Then run net start serviceName (administrative credential is needed)
I've been working with Microsoft Service Fabric since November 2015 and have encountered many issues but now Service Fabric has become completely non-functional on my development machine. Uninstall/reinstall doesn't help.
I was using 1.5-preview and have since tried 2.0 to no avail.
The problem started when I attempted to run a Service Fabric Application from Visual Studio 2015 Update 1 (as I have done hundreds of times over the past few months).
My machine blue-screened (first time I've seen a Windows 10 blue screen). After rebooting, I was unable to get my Service Fabric Application to deploy via Visual Studio. The PowerShell script failed with the following message:
Starting service FabricHostSvc. This may take a few minutes...
Start-Service : Failed to start service 'Microsoft Service Fabric Host
Service (FabricHostSvc)'.
I went into the SCM and found "Microsoft Service Fabric Host Service" was in a state of Starting. It stayed that way for an hour. I tried stopping and starting the service several times and each time it hangs.
I uninstalled Service Fabric (Service Fabric, SDK and Tools for VS) and re-installed with the latest version 2.0 and it exhibits the same problem.
Reboot, same problem.
Removed c:\SfDevCluster folder, same problem.
Based on some other articles, I looked for any stray performance counters after uninstalling but there weren't any.
I tried looking through the registry but there are other Azure components with "Fabric" in the name. If I delete them, I will probably hose the rest of my Azure dev setup.
Now... when I attempted to start the service again, it did re-create the SfDevCluster folder and give me some logs. It seems to create two trace log files per minute and they have the EXACT same contents.
Every time it fails, the final line of the trace is:
Info ,11176,General.FabricSetup.Main,Operation failed with error
0xffffffff
An earlier trace (SF 1.5) seemed to use a constant rather than the hex value for the error. Seemed to indicate an invalid argument.
Whatever this failure is, it seems to be the cause of my woes. Unfortunately, the error is completely unhelpful.
I'm trying to avoid reinstalling Windows because that will kill an entire day of productivity.
Any help is greatly appreciated.
From an elevated powershell session please run: Unregister-ScheduledTask FabricCounters.
This will fix the issue.
I was seeing very similar behaviour and reinstalls of the fabric SDK and runtime, deleting scheduled tasks, deleting the SfDevCluster contents etc. all didn't work.
I was seeing repeated Docker errors in the event log and when I tried uninstalling Docker for Windows SF instantly woke up. I have no idea what the interaction is between the two but worth checking if you have both installed.
For the benefit of searchers, this is the Powershell script I use to fix my local cluster. It was adapted from this issue fix on github.
#
# WARNING: YOU MUST STOP 'SERVICE FABRIC HOST SERVICE' IN SERVICES FIRST
# IF THE APPLICATION IS STUCK IN 'STARTING', RESTART YOUR MACHINE
#
# This script will completely reset the local cluster
#
Remove-Item 'C:\SfDevCluster' -Recurse -Force -ErrorAction Stop
New-Item -ItemType directory -Path 'C:\SfDevCluster'
Set-Location 'C:\Program Files\Microsoft SDKs\Service Fabric\ClusterSetup'
./DevClusterSetup.ps1 -PathToClusterDataRoot 'C:\SfDevCluster\Data' -PathToClusterLogRoot 'C:\SfDevCluster\Log'
C:\ drive was full for me. Easy thing to overlook.
Make sure your hard disks aren't full... that was stopping mine from starting. Immediately after clearing up some logs, starts up right away.
It seems like some cluster related settings have gone into an inconsistent state on your machine. This will require looking at Service Fabric traces and figure out the actual cause. I am an engineer on the Service Fabric team. I can help you out if you can email me the Service Fabric traces (from logs folder) at harahma[at]microsoft[dot]com.
If you are familiar with logging support tickets on Azure, I would suggest you do that too so we can track this issue to resolution. In the meantime I will continue to work on this to see how we can unblock you.
I know this is an old and question, but maybe my pain can help someone else out.
You'll get a similar error if the Windows Firewall service is not running when Service Fabric attempts to start.
Check and make sure that the Windows Firewall service is set for Automatic and is running.
I have tried multiple options to resolve this issue like
Uninstall runtime and SDK - Reinstall it.
Removed cluster using powershell commands and setup using the same
and there are couple of more
BUT unfortunately none of them worked for me
Then finally I have Uninstalled Docker Desktop and suddenly issue got resolved.
This is very strange and not sure how docker desktop is obstackle for running FabricHostSvc Service.
I'm trying to get my head around WCF applications hosted as a Windows service but I'm not sure what's happening here.
Basically, to get started, I've got a literal copy and paste of the code in this article: (I know, I shouldn't)
https://msdn.microsoft.com/en-us/library/vstudio/ms733069%28v=vs.110%29.aspx
The service builds fine and I can install it without issue. It shows up in services.msc also. I'm installing it as follows: (from the visual studio command prompt)
installutil Service.exe
However when it runs, I get the following error:
The WCFWindowsServiceSample service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.
What am I doing wrong?
So until recently i have been testing my program which uses async sockets to send and receive data without problems but today suddenly it stoped working. After a lot of wasted time testing stuff and figuring out why the old version with practicly identical source code(copyed whole project folder) worked. Finnaly i figured out that windows firewall decided, for whatever reason, to block the exe again. If i go to the project folder and run is as admin it works fine (after accepting the firewall warning), but when i run it from within VS2010 in debug mode i get no warning and stuff just doesnt work.
So how do i allow the application when its running in debug mode through the firewall?
You say it works if you run the exe as an administrator, so what happens if you run Visual Studio as an administrator?
I fixed it with renaming the project folder in Projects/ and it worked again without any need to allow the program through the firewall again
So, this interesting issue has been plaguing me for the past couple of hours. Visual Studio 2010 Ultimate no longer attaches the debugger and lets me debug my code.
If I use the built in development server, then everything works fine. If I switch to Use Local IIS Web Server (http://localhost/), then all it does it attach to w3wp.exe, but no DLLs or PDBs are loaded for anything. I can go to Debug > Windows > Modules, and literally nothing is loaded in this window. Conversely, when using the built in development server, the Modules window displays all the DLLs and shows that the symbols for my DLLs have been loaded. Something is obviously amiss. The VS installation is completely bone stock.
In IIS, my website is configured with ASP.NET 2.0 (because no 3.5 exists to select from the drop down), along with read / log visits / index this resource options checked on the "Home Directory" tab.
Some of my failed ideas:
1) If I attach to process on the iexplore.exe instance where the website is displayed, it loads Internet Explorer's DLLs, but not mine.
2) I've restarted the computer multiple times
3) I've invoked devenv.exe /resetuserdata once
4) I've confirmed that every project is indeed set to debug and not release.
5) Deleted all \bin contents and rebuilt the solution.
6) Deleted entire solution and repulled from Source Control.
Can someone tell me what is wrong with this thing? I'm going to have an aneurism from the headache this is causing me.
You need to attach it to the IIS worker process, which OS are you using? Make sure you attach with the Managed + Native flags, in the Attach to Process. What happens if you just run (F5) your web application inside Visual Studio (that automatically attaches a debugger)? Do you get any errors?
Well there are quite a few good answers here, but I have found that the root cause of the issue for me was application pool authentication configuration. Let me lay out the scenario that I experienced and the solution and perhaps it will help someone save time....and hair.
Scenario:
I want to debug an ASP.NET web application in Visual Studio 2010 but cannot use the built-in Visual Studio web server. The reason that I could not use the built-in web server is that my application referenced assemblies built specifically for a 64-bit architecture and the VS web server would not support these. So, I had to use the option "Use Custom Web Server" in the website properties to point the debugger at a published instance of my site on a remote IIS web server.
Issue:
Even with the web.config debug options set correctly to publish debug symbols in the assembly output (i.e. compilation debug="true"), the debugger would not attach to the remote IIS process and I did not hit any breakpoints
Environment:
The Visual Studio 2010 debugger was already installed on the remote IIS web server and was running as a Windows service under the LocalSystem account.
Solution:
Enable "Anonymous Authentication" in addition to "Windows Authentication" on the web site hosted on the IIS web server.
As soon as I enabled anonymous authentication, the correct symbols were loaded by the VS remote debugger and I was able to hit the breakpoints.
Hope this helps you guys out.
Have you tried deleting the browser cache? Sometimes the browser hangs on to old code which is incompatible with the current build and thereby prevents debugging.
Does it run the app - without the debugger attached? It smells like you are attaching the debugger to a wrong process
I've had an issue before where under the build configuration screen some projects are unticked for a particular solution configuration, causing them to not build and therefore not be debuggable. Can you confirm whether or not code changes you make are actually being built and executed?
Also, what version of Windows and IIS are you running? Is it possible that your process is running under an AppPool with an account that's different to the account you're logged in with and perhaps it's a permissions problem? If it's Vista/Win7, is UAC turned on and are you running VS as administrator? I'll also second the suggestion to try a fresh project and see what that does. Are you in the debugger users local group on the machine?