Deleting a file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I get the exception System.UnauthorizedAccessException: Access to the path "c:\Some.dll" is denied. when trying to delete a file

I am loading the dll with Assembly.Load(...) then using Invoke to call some code in one of the public static methods of a type

After this I need to delete the file but get the exception.

How can I release the hold on the file so I can delete it

Thank you
 
Hi Sid,

IIRC that is not the exception it's rise when you try to delete an open
file, it said something about the file is in use by other process.
I think that your problem is other, maybe you do not have permission to
delete the file , or maybe you are running your application from a network
path.


Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Sid Sidney said:
I get the exception System.UnauthorizedAccessException: Access to the path
"c:\Some.dll" is denied. when trying to delete a file.
I am loading the dll with Assembly.Load(...) then using Invoke to call
some code in one of the public static methods of a type.
 
In order to release the file, you need to unload the assembly. In order to
do that, load the assembly into a separate AppDomain and then unload the
domain before you delete the file.

Alternatively, you could turn on shadow copying
(AppDomain.SetShadowCopyFiles). This way you can keep the (shadow copied)
assembly loaded in memory and still delete the original assembly file.

hth,
Sami
www.capehill.net




Sid Sidney said:
I get the exception System.UnauthorizedAccessException: Access to the path
"c:\Some.dll" is denied. when trying to delete a file.
I am loading the dll with Assembly.Load(...) then using Invoke to call
some code in one of the public static methods of a type.
 
Back
Top