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 / .NET Framework / New Users / January 2007

Tip: Looking for answers? Try searching our database.

Reflection and DirectoryInfo.Delete error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
goHawkeyes - 26 Jan 2007 22:41 GMT
After using System.Reflection.Assembly.ReflectionOnlyLoadFile to look
through a directory and inspect versions of files and such I use a
DirectoryInfo.Delete(True) object to delete the directory but it gives
me an unauthorized error.  If I do everything the same way but do not
inspect the directory contents with reflection I can delete the
directory.  I have tried setting my assembly variable to nothing as
well as force garbage collection yet nothing seems to fix the problem.
Is there a bug here or am I missing something?

Thanks,

AJL
Ollie Riches - 29 Jan 2007 10:13 GMT
If you are using System.Reflection.Assembly.ReflectionOnlyLoadFile to list
the contents of directory where an assembly is loaded for your application
then you are going to have to unload the assembly loaded from that directory
before attempting to delete the directory. If this is the case then why
would you want to delete the directory.

HTH

Ollie Riches

> After using System.Reflection.Assembly.ReflectionOnlyLoadFile to look
> through a directory and inspect versions of files and such I use a
[quoted text clipped - 8 lines]
>
> AJL
goHawkeyes - 29 Jan 2007 15:14 GMT
Here is the solution I found.  I didn't realize I could not easily
unload the assembly from my appDomain.  One work around is below,
sorry I couldn't find the originally group link.  You basically make a
copy of the file so as not to load the originally into the appdomain.

Private Function GetDllInfo(ByVal filePath As String) As DllInfo

       Dim asm As Assembly
       Dim dllVersionInfo As New DllInfo

       Dim stream As New FileStream(filePath, FileMode.Open,
FileAccess.Read)
       Dim memstream As New MemoryStream()

       Dim b(4096) As Byte

       While stream.Read(b, 0, b.Length) > 0

           memstream.Write(b, 0, b.Length)

       End While

       asm = Assembly.Load(memstream.ToArray())

       dllVersionInfo.DllVersion = asm.GetName.Version.ToString
       dllVersionInfo.DllName = asm.GetName.Name.ToString

       memstream.Close()
       stream.Close()

       Return dllVersionInfo

   End Function

Public Class DllInfo

       Dim version As String
       Dim name As String

       Public Sub New()
       End Sub

       Public Property DllVersion() As String
           Get
               Return version
           End Get
           Set(ByVal value As String)
               version = value
           End Set
       End Property

       Public Property DllName() As String
           Get
               Return name
           End Get
           Set(ByVal value As String)
               name = value
           End Set
       End Property
   End Class

> If you are using System.Reflection.Assembly.ReflectionOnlyLoadFile to list
> the contents of directory where an assembly is loaded for your application
[quoted text clipped - 18 lines]
>
> > AJL- Hide quoted text -- Show quoted text -

Rate this thread:







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.