VB.NET Parameter is not valid
<p>I have used dotnetbar devcomponents advanced treeview to create multiple directory trees for one of my projects. Functionality wise, everything is working fine. </p>

<p>I have now added images to the directory file nodes (e.g. pdf image if its a pdf file) and published the application. The application runs without any errors first time on any machine, but once I close this File Management form (I have a control panel form with buttons that is the initial startup form. The buttons take me to other forms. On button click, it hides the control panel and displays the corresponding form through showdialog - File Management form is one of those buttons) and reopen it again - I get the following error:</p>

<p><a href="http://i.stack.imgur.com/GaqWS.png" rel="nofollow">parameter_is_not_valid</a></p>

<p>It then fails to load the nodes and after a couple of tries, Microsoft .Net Framework window appears and ends the application.</p>

<p>I get the images from my resource file. Please see the code for LoadAllSubDirectoriesFiles where the error occurs:</p>

<pre><code>    Private Sub LoadAllSubDirectoriesFiles(ByVal uParent As DevComponents.AdvTree.Node)
    ' Initialise Error Checking
    Dim uStackframe As New Diagnostics.StackFrame
    Dim ufile As IO.FileInfo = Nothing
    Try

        If uParent.Name.Length &lt;&gt; 248 Then

            Dim files As IO.FileInfo() = uParent.Tag.GetFiles()

            For Each file As IO.FileInfo In files
                If (Not file.Attributes.ToString.Contains("Hidden")) Then
                    Dim uNode As DevComponents.AdvTree.Node = New DevComponents.AdvTree.Node()
                    uNode.Tag = file
                    uNode.Name = file.FullName.ToLower
                    uNode.Text = file.Name
                    If file.Extension = ".msg" Then
                        uNode.Image = My.Resources.Resources.Mail3
                    ElseIf file.Extension = ".txt" Then
                        uNode.Image = My.Resources.Resources.Document
                    ElseIf file.Extension = ".pdf" Then
                        uNode.Image = My.Resources.Resources.pdf
                    ElseIf file.Extension = ".doc" OrElse file.Extension = ".docx" Then
                        uNode.Image = My.Resources.Resources.doc
                    ElseIf file.Extension = ".xlsx" Then
                        uNode.Image = My.Resources.Resources.excel
                    ElseIf file.Extension = ".pub" Then
                        uNode.Image = My.Resources.Resources.publisher
                    ElseIf file.Extension = ".pptx" Then
                        uNode.Image = My.Resources.Resources.powerpoint
                    ElseIf file.Extension = ".bmp" OrElse file.Extension = ".png" OrElse file.Extension = ".jpg" OrElse file.Extension = ".gif" OrElse file.Extension = ".tif" Then
                        uNode.Image = My.Resources.Resources.bitmap_image
                    ElseIf file.Extension = ".zip" OrElse file.Extension = ".rar" Then
                        uNode.Image = My.Resources.Resources.zip
                    Else
                        uNode.Image = My.Resources.Resources.unknown
                    End If
                    uNode.DragDropEnabled = True
                    uParent.Nodes.Add(uNode)
                End If
            Next
        End If
    Catch ex As Exception
        ' Catch Error
        If Err.Number &lt;&gt; 0 Then
            WriteAuditLogRecord(uStackframe.GetMethod.DeclaringType.FullName, uStackframe.GetMethod.Name.ToString, "Error", ex.Message &amp; vbCrLf &amp; vbCrLf &amp; ex.StackTrace, 0)
            MsgBox("System Error Ref: " &amp; sAuditID &amp; vbCrLf &amp; uStackframe.GetMethod.DeclaringType.FullName &amp; " / " &amp; uStackframe.GetMethod.Name.ToString &amp; vbCrLf &amp; ex.Message &amp; vbCrLf &amp; vbCrLf &amp; ex.StackTrace &amp; Chr(13) &amp; sErrDescription &amp; vbCrLf &amp; vbCrLf &amp; "Press Control + C to copy this error report", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Business Management System - Unexepected Error Ref: " &amp; sAuditID)
        End If

    Finally
        ' CleanUp

    End Try

End Sub
</code></pre>

<p>I have spent 2 days now trying to figure out the cause and fix for this problem. There were posts that talked about the image being disposed and not being able to retrieve the image reference [ <a href="http://blog.lavablast.com/post/2007/11/29/The-Mysterious-Parameter-Is-Not-Valid-Exception.aspx" rel="nofollow">http://blog.lavablast.com/post/2007/11/29/The-Mysterious-Parameter-Is-Not-Valid-Exception.aspx</a> ] , cloning the image before disposing etc.
I have given disposing and cloning a go, but the error still stands. Been trying couple of other things, but still unsuccessful.</p>

<p>Any suggestions to what is wrong? </p>

<p><strong>EDIT 1</strong>
Before closing the form, I clear all the treenodes and then use Me.Close()</p>

<pre><code>    Private Sub tsbClose_Click(sender As Object, e As EventArgs) Handles tsbClose.Click
    atRootFolder.Nodes.Clear()
    atAllDirectories.Nodes.Clear()
    atScannedFiles.Nodes.Clear()
    atFiles.Nodes.Clear()
    atInbox.Nodes.Clear()
    atSent.Nodes.Clear()
    Me.Close()
End Sub
</code></pre>

<p><strong>EDIT 2</strong>
My treeviews have hundreds of nodes, child nodes etc. Please see the image of my File Management form ( this is the first time it was loaded, no errors) I had to hide the text due to client confidentiality, but I hope it makes sense. Each image is a node.</p>

<p>imgur.com/QQ2FzFV</p>