Guys I hope you can help me as this is driving me mad.
I have written an installer. This installer installs a service.
If I release an upgrade to my app, the installer is meant to overwrite the existing files. What I have done is check to see if the 'service' file exists in the destination folder if it does it checks to see if the service is installed then uninstalls it before overwriting the 'service' file. Hope that isn't too confusing! The problem is this bit of code as far as I can tell:

using (installer = new System.Configuration.Install.AssemblyInstaller(wservice, new string[] { }))
                {
                    installer.Uninstall(saveState);
                }

When it returns to the 'copy' method, the lock on the 'service' file hasn't been released(even though the service has been uninstalled) and therefore when it tries to overwrite the file it fails saying that the file is being used by another process.

Any help would be gratefully received.

Matt.

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

Come on guys, someone must have a big enough brain to sort this one out:)

Matt,

Did you ever find a solution to this issue? I am doing the exact same thing and experiencing the exact same issue. If I run InstallUtil.exe to add/remove my service it works fine. But when I use AssemblyInstaller to uninstall the service, a file handle is left open to the service exe. The file in turn is not deletable or overwritable. Please let me know how/if you got by this and I will do the same.

Thanks.

The solution is to create a new, temporary AppDomain. Use the new AppDomain to instatiate an object that uses AssemblyInstaller to install and/or uninstall your assembly. This wasted a day of development time figuring this out. If you need to know how to do this, just google "Creating an AppDomain" and you should find the results you need. Don't forget to Unload the new appdomain when you're done with it.

This article has been dead for over six months. Start a new discussion instead.