-
AssemblyInstaller
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.
-
Re: AssemblyInstaller
Where is the code that handles the uninstallation of the wservice? Is it correctly releasing handles to the file after deletion (ie: using())?
-
Re: AssemblyInstaller
Thanks very much for replying.
The method that calls the forementioned one is as follows but I cannot see that there would be any locks:
private void recursiveCopy(string dirSource, string dirDest)
{
string[] files = Directory.GetFiles(dirSource);
if (!Directory.Exists(dirDest)) // Create directory
{
Directory.CreateDirectory(dirDest);
}
foreach (string file in files) // Copy files
{
FileInfo fi = new FileInfo(file);
string serviceName = "ScheduleImportService.exe";
if (fi.Name == serviceName)
{
string serviceFileName = Path.Combine(dirDest, serviceName);
if (File.Exists(Path.Combine(dirDest, serviceName)))
{
uninstallService(serviceFileName);
}
}
File.Copy(file, Path.Combine(dirDest, fi.Name), true);
}
string[] dirs = Directory.GetDirectories(dirSource);
foreach (string dir in dirs)
{
DirectoryInfo di = new DirectoryInfo(dir);
recursiveCopy(dir, Path.Combine(dirDest, di.Name));
}
}
As you can see I check for a filename if it exists I remove the service then 'try' to delete the file which fails.
Hope you can help.
Matt.
-
Re: AssemblyInstaller
Nothing calls out to me at the moment. I may take some time today to replicate a simple use case of this and see if I can repro it.
I also suggest you write a simple test case for this scenario as well, as it does seem pretty easily reproducable without a service and all that.
-
Re: AssemblyInstaller
Ensure that the service is not running.
-
1 Attachment(s)
Re: AssemblyInstaller
Thanks for replying you guys, I have made sure I have stopped the service and I have attached a test solution which does exactly the same thing.
Any continued help would be great.
-
Re: AssemblyInstaller
I forgot to mention that for this example project I create 2 folders a source and a destination. In the source I would put the ServiceTest and the WindowsServiceTest.
Please help, I have tried all I can think of.