Friday, December 21, 2007

If you're building a C# webservice...

...and you've given your service an auto-installer you may run into the problem I ran into today. Hopefully I can save you the immense frustration I experienced by leaving this tip for you.

When you build your service and see something like:


Microsoft.Common.targets(3090,13): error MSB3073: The command "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil.exe -u "C:\Users\hans\Desktop\Process Manager\Process Manager.exe" "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(3090,13): error MSB3073: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil.exe "C:\Users\hans\Desktop\Process Manager\Process Manager.exe"" exited with code -1.

Don't bother googling, don't bother reading Microsoft's support site(s), don't bother combing enwsgroups. Just make sure you don't have a process instance of your service running in the background, then open a command prompt (as Administrator) and use the SC.exe utility to delete your service from the services list. If you get 'Access Denied' ensure, again, that you don't have a process instance of your service running. You will likely get past the 'Access Denied' and either get a success message or a message saying the service is not registered so it could not be deleted. Either way you're fixed now. Try rebuilding your service again. This most often arises if you're using the 'Debug version of service run as normal application instead of service' debugging trick.

This was driving me crazy earlier this week and I don't want to try to remember it in 12 months when it happens to me again...

P.S. 'Access Denied' reported by SC.exe after you've killed any errant process instances usually means that the Services.msc component (the services applet) is open and was hung trying to start it. Just close the applet and try the "SC.exe delete "" command again and you'll be golden.

3 comments:

  1. Thanks for the tip! I was just about to build a C# web service, right after I finished frosting my Mandarin Orange Coconut Cake.

    ReplyDelete
  2. lol - hey, I didn't say it was a useful tip for most people... ;)

    ReplyDelete
  3. Exactly what I needed, THANKS!

    In the end I modified my post-build event to be:

    REM "Deleting the service (if it already exists)
    sc delete myservice

    REM "Installing the Service into the System"
    "C:\Windows\Microsoft.NET\Framework\v2.0.50727\installutil.exe" "$(TargetPath)"

    ReplyDelete