CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2010
    Posts
    14

    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.

  2. #2
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    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())?

  3. #3
    Join Date
    Feb 2010
    Posts
    14

    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.

  4. #4
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    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.

  5. #5
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: AssemblyInstaller

    Ensure that the service is not running.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  6. #6
    Join Date
    Feb 2010
    Posts
    14

    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.
    Attached Files Attached Files

  7. #7
    Join Date
    Feb 2010
    Posts
    14

    Unhappy 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured