Home All Groups Group Topic Archive Search About

CheckIfInstallable method locks the file

Author
4 Jul 2006 11:08 PM
Stefano
Hi all,
when I try to use the CheckIfInstallable  method of
System.Configuration.Install.AssemblyInstaller on a file not installable, I
correctly get an exception, but then the file checked remains locked by the
application until I close the program (e.g. I can't delete the file or
overwrite it).

Why the file remains locked? Is there a way to avoid it?

Author
4 Jul 2006 11:21 PM
Greg Young
It is because Assembly.Load is run on the file (the assembly gets loaded
into your appdomain).

You can see this in the Path setter it uses

      set
      {
            if (value == null)
            {
                  this.assembly = null;
            }
            this.assembly = Assembly.LoadFrom(value);
      }



This will hold a lock on the file until the appdomain is killed.

No way to work around this I'm afraid except to wait until the appdomain is
dead to delete the file.
Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

Show quote
"Stefano" <n*@no.it> wrote in message
news:e9KYJ77nGHA.2264@TK2MSFTNGP04.phx.gbl...
> Hi all,
> when I try to use the CheckIfInstallable  method of
> System.Configuration.Install.AssemblyInstaller on a file not installable,
> I correctly get an exception, but then the file checked remains locked by
> the application until I close the program (e.g. I can't delete the file or
> overwrite it).
>
> Why the file remains locked? Is there a way to avoid it?
>
Author
4 Jul 2006 11:26 PM
Greg Young
I would put this up as a suggestion

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

Show quote
"Greg Young" <druckdruckREMOVEgo***@hotmail.com> wrote in message
news:eM24eC8nGHA.4736@TK2MSFTNGP02.phx.gbl...
> It is because Assembly.Load is run on the file (the assembly gets loaded
> into your appdomain).
>
> You can see this in the Path setter it uses
>
>      set
>      {
>            if (value == null)
>            {
>                  this.assembly = null;
>            }
>            this.assembly = Assembly.LoadFrom(value);
>      }
>
>
>
> This will hold a lock on the file until the appdomain is killed.
>
> No way to work around this I'm afraid except to wait until the appdomain
> is dead to delete the file.
> Cheers,
>
> Greg Young
> MVP - C#
> http://codebetter.com/blogs/gregyoung
>
> "Stefano" <n*@no.it> wrote in message
> news:e9KYJ77nGHA.2264@TK2MSFTNGP04.phx.gbl...
>> Hi all,
>> when I try to use the CheckIfInstallable  method of
>> System.Configuration.Install.AssemblyInstaller on a file not installable,
>> I correctly get an exception, but then the file checked remains locked by
>> the application until I close the program (e.g. I can't delete the file
>> or overwrite it).
>>
>> Why the file remains locked? Is there a way to avoid it?
>>
>
>
Author
5 Jul 2006 6:51 AM
Damien
Greg Young wrote:
Show quote
> It is because Assembly.Load is run on the file (the assembly gets loaded
> into your appdomain).
>
> You can see this in the Path setter it uses
>
>       set
>       {
>             if (value == null)
>             {
>                   this.assembly = null;
>             }
>             this.assembly = Assembly.LoadFrom(value);
>       }
>
>
>
> This will hold a lock on the file until the appdomain is killed.
>
> No way to work around this I'm afraid except to wait until the appdomain is
> dead to delete the file.
>
So, to help the OP, he could:
1) Create a second AppDomain
2) Load either his existing code assembly or just a simple stub one in
3) Create a class in the second domain
4) Call a method on that class which performs the original
CheckIfInstallable check and returns a boolean
5) Unload the second AppDomain

correct?

Damien
Author
5 Jul 2006 9:09 AM
Stefano
Ok, thanks to everybody, I've called the method from a second AppDomain and
everything worked!

Show quote
"Damien" <Damien_The_Unbelie***@hotmail.com> wrote in message
news:1152082263.593621.226570@p79g2000cwp.googlegroups.com...
> Greg Young wrote:
>> It is because Assembly.Load is run on the file (the assembly gets loaded
>> into your appdomain).
>>
>> You can see this in the Path setter it uses
>>
>>       set
>>       {
>>             if (value == null)
>>             {
>>                   this.assembly = null;
>>             }
>>             this.assembly = Assembly.LoadFrom(value);
>>       }
>>
>>
>>
>> This will hold a lock on the file until the appdomain is killed.
>>
>> No way to work around this I'm afraid except to wait until the appdomain
>> is
>> dead to delete the file.
>>
> So, to help the OP, he could:
> 1) Create a second AppDomain
> 2) Load either his existing code assembly or just a simple stub one in
> 3) Create a class in the second domain
> 4) Call a method on that class which performs the original
> CheckIfInstallable check and returns a boolean
> 5) Unload the second AppDomain
>
> correct?
>
> Damien
>

AddThis Social Bookmark Button