Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2004

Tip: Looking for answers? Try searching our database.

Why can't I delete this file? Does Assembly.LoadFile leave it lock

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
M K - 29 Jul 2004 18:52 GMT
In my Windows Form, I have a io.File.Delete(filePath) command. Everyone has Full Control to the folder and file. I watch the file with FileMon and nothing opens the file in my code. (There is no code to open the file before the delete command.) I get an 'UnauthorizedAccessException'.

How can I find out what's causing this exception. What could keep me from deleting the file. Please help. This, should be, simple thing is holding up production.

I cannot delete the file while my app is running. Why?

I have this in my code before the File.Delete command:
    Dim myAssem As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile(thisPath & "\" & drCurrent("FileName"))
    currentVersion = myAssem.GetName.Version
       ...'Save the Version to a dataTable
    myAssem = Nothing

Could this be locking my file? If so, how do I unlock it?
Lloyd Sheen - 29 Jul 2004 19:22 GMT
The load assembly is locking the code.  I have found (or not found a way
around it) that the only way to do this is to load the file into a byte
array and then load assembly from the byte array.

Lloyd Sheen

Code sample:
Private Function GetTextConverterAssembly(ByVal rsType As String) As
[Assembly]
 Dim poBytes() As Byte = GetTextConverterByteCode(rsType)
 Return [Assembly].Load(poBytes)
End Function

Private Function GetTextConverterByteCode(ByVal rsType As String) As Byte()
 Dim psLangFile As String
 psLangFile = Path.GetDirectoryName(Application.ExecutablePath)
 psLangFile += "\TextConverters\TextConverter." + rsType + ".dll"
 Dim fs As FileStream = New FileStream(psLangFile, FileMode.Open,
FileAccess.Read)

 Dim TS As New BinaryReader(fs)
 Dim poBytes() As Byte
 poBytes = TS.ReadBytes(CInt(fs.Length))
 TS.Close()
 Return poBytes
End Function

> In my Windows Form, I have a io.File.Delete(filePath) command. Everyone has Full Control to the folder and file. I watch the file with FileMon and
nothing opens the file in my code. (There is no code to open the file before
the delete command.) I get an 'UnauthorizedAccessException'.

> How can I find out what's causing this exception. What could keep me from deleting the file. Please help. This, should be, simple thing is holding up
production.

> I cannot delete the file while my app is running. Why?
>
[quoted text clipped - 5 lines]
>
> Could this be locking my file? If so, how do I unlock it?
Stoitcho Goutsev \(100\) [C# MVP] - 29 Jul 2004 19:31 GMT
M K,

Since when load an assembly it cannot be unload it make sense that CLR keeps
the file open so nobody can delete it.

Signature

Stoitcho Goutsev (100) [C# MVP]

> In my Windows Form, I have a io.File.Delete(filePath) command. Everyone has Full Control to the folder and file. I watch the file with FileMon and
nothing opens the file in my code. (There is no code to open the file before
the delete command.) I get an 'UnauthorizedAccessException'.

> How can I find out what's causing this exception. What could keep me from deleting the file. Please help. This, should be, simple thing is holding up
production.

> I cannot delete the file while my app is running. Why?
>
[quoted text clipped - 5 lines]
>
> Could this be locking my file? If so, how do I unlock it?
M K - 29 Jul 2004 20:23 GMT
So, I guess that's not a good way to look at an assembly's Version. Is there another way to look at an assembly's version?

"Stoitcho Goutsev (100) [C# MVP]" wrote:

> M K,
>
[quoted text clipped - 20 lines]
> >
> > Could this be locking my file? If so, how do I unlock it?
Stoitcho Goutsev \(100\) [C# MVP] - 29 Jul 2004 23:25 GMT
Hi M K,

You can read all the assembly info without loading it via AssemblyName class

AssemblyName an = AssemblyName.GetAssemblyName(<your assembly file name>);
Console.WriteLine(an.Version.ToString());

Signature

HTH
Stoitcho Goutsev (100) [C# MVP]

> So, I guess that's not a good way to look at an assembly's Version. Is there another way to look at an assembly's version?
>
[quoted text clipped - 24 lines]
> > >
> > > Could this be locking my file? If so, how do I unlock it?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.