I have a windows service that worked properly when the target framework is .NET 2, when I changed it to .Net 4 I recompiled the project, re-installed it using installutil then started the service but I'm getting "Windows could not start the service on Local Computer. Error 1067: The process terminated unexpectedly." Not sure how to proceed, the OnStart() method is not being hit by the Debugger.Break() line. Any idea how to proceed? Is there some settings or configuration I need to update if I change the target framework?
3
votes
The project probably didn't get fully recompiled when switching from Net 2 to Net 4. The dependencies of the compiler doesn't always recognize changes in options. The best way to solve issue is to delete the bin folder in the project and recompile. The compiler will recreate the bin folder.
– jdweng
@jdweng Thanks for the suggestion! i tried it but still got the same issue. It's really weird because when I change it back to .NET 2 and re-compile, I don't get any problems at all. Hmmmm...
– whastupduck
Check the event log
– Emond Erno
My guess is your using the .Net 4.0 Client Profile - use the Full Framework.
– Jeremy Thompson
Are you able to run the exe as a console?
– NY-M
2 Answers
1
votes
Some things to check
- When you uninstalled the 2.0 version did it completely uninstall? Check Control Panel|Services to see if it is removed. Reboot in between to make sure that is uninstalled correctly.
- Are you using the correct installutil.exe for 4.0? Also correct 32 Bit/64 bit version for the machine and application?
- When you switched from 2 to 4, did it correctly change the startup object? Check the project properties and make sure the correct startup object is selected.
1
votes
Here the somethings I would do to troubleshoot the issue
- Check application event logs and error logs on the computer where you tried to start the service
- If the service failed on the server its better to get the service installed on your local developer machine to debug the issue
- Launch the services console as an administrator and make sure the account under which service is starting has a valid user name and password
- Open the Windows service in the Visual Studio
- Check the advance compile options to see if its .NET framework 4.0 and which version of operation system is being used 32 bit or 64 bit
- Clean and rebuild the solution
- Put a breakpoint in the OnStart method and debug the service. If the service is running periodically on a timer adjust the time interval as needed so it would be easy to debug. Sometimes we will have to attach a process
- If the service is working on your machine and not working on the service using remote debugging might help to resolve the issues
- Unistall all the previous versions of the service and make sure there is one active version of service running at one point of time
- When you uninstalling, installing the service or using the visual studio launch it as administrator and also pay attention to the user account under which service is running.