Error 1001: Source 'ServiceName' already exists on local computer

by Marvin 19. March 2010 03:59

When trying to install a service I am developing locally on my laptop, I was getting an error "Error 1001: Source 'ServiceName' already exists on local computer" and the install was unsuccessful.  After about an hour of binging and googling, I figured out the solution.  

I've been working on this Windows Service for awhile.  I have been uninstalling old versions and installing new versions without a hitch.  For me, that process has looked like this.  I stop the service.  I then right-click my setup project in Visual Studio 2008 Pro and choose uninstall.  After doing this, the service will not be listed in either Start > Control Panel > Administrative Tools > Services or Visual Studio's Server Explorer > Computer Name > Services.  I then right-click the setup project in VS to install, and the installation usually completes just fine.  Then I go into Start > Control Panel > Administrative Tools > Services, find the service, right-click it and start it.
 
With this latest version, though, the install started but failed with the error "Error 1001: Source 'ServiceName' already exists on local computer." where 'ServiceName' is the name I've given to the service.

So, I decided to try uninstalling the service manually after the fact using C:\WINDOWS\Microsoft.NET\Framework\v2.050727\installutil as described here thinking that maybe the manual uninstall will get rid of whatever source the error is referring to, but I got a System.IO.FileNotFoundException.  Makes sense to me.  The service is uninstalled after all.  So, why the heck am I getting this goofy source error!?

I think I found the solution in the comments of this article:
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.sourceexists.aspx

It seems that the critical point that broke things for me was this.  I was trying to use the EventLog in my service, and I used the actual service name in code to create event source in the event log.  This was essentially the code that did this.

            try
            {
                if (!EventLog.SourceExists("ServiceName"))
                    EventLog.CreateEventSource("ServiceName", "CompanyName");
            } catch (Exception) { }
            eventLog = new EventLog();
            eventLog.Source = "ServiceName";

Apparently, I should not have done that.  So, as suggested, I renamed my service but did not rename the name I gave to the service in the Event Log.  Now, I have a slightly different service name that the name used here in place of "ServiceName", if that makes any sense. 

I don't know if it was really necessary, but I also removed my existing setup project from the solution and recreated one using the instructions here:
http://msdn.microsoft.com/en-us/library/zt39148a(VS.80).aspx

After doing all this, I was able to install the service again.
 
Addendum
 
After doing all of the above, when I came around the next time to uninstall and reinstall, I had a new problem.  I uninstalled the service with installutil, but when I tried to install the new service, I got an error saying it was already installed, and that I should use Add/Remove Programs to remove it.  When I tried that, I got an "Error 1001. An exception occurred while uninstalling. This exception will be ignored and the uninstall will continue. However, the application might not be fully uninstalled after the uninstall is complete." followed by a "fatal" error which aborted the uninstall.  
 
More googling.  I found descriptions of similar trouble:
http://discuss.joelonsoftware.com/default.asp?dotnet.12.430318.3
http://www.daniweb.com/forums/thread86367.html#
 
The latter had a suggestion which worked for me.  I simply used installutil again to reinstall the exe file for the service (which was still in the folder it was originally installed to), and then uninstalled the service using Add/Remove Programs which worked this time without a problem.
 
Based on this little adventure, I've decided installutil is crap. 

Currently rated 4.8 by 12 people

  • Currently 4.833333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



About the author

I am a junior-level C# .NET developer living in Nashville, TN.  I'm currently working in biomedical informatics, developing a web service, a MySql database, and a web application.  Every week or so, I spend hours trying to figure out how to do something, and after I find the solution, I really want to make sure I don't go through that exercise again.  I love to write.  It helps me to remember things.  So, I use this blog as a way to document those painful lessons as I learn them.  It has already helped me to be able to refer back to them.  I hope some of these will save someone else some time as well.