Search code examples
vb.nettreeviewdotnetbar

VB.NET Parameter is not valid


I have used dotnetbar devcomponents advanced treeview to create multiple directory trees for one of my projects. Functionality wise, everything is working fine.

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:

parameter_is_not_valid

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

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

    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 <> 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 <> 0 Then
            WriteAuditLogRecord(uStackframe.GetMethod.DeclaringType.FullName, uStackframe.GetMethod.Name.ToString, "Error", ex.Message & vbCrLf & vbCrLf & ex.StackTrace, 0)
            MsgBox("System Error Ref: " & sAuditID & vbCrLf & uStackframe.GetMethod.DeclaringType.FullName & " / " & uStackframe.GetMethod.Name.ToString & vbCrLf & ex.Message & vbCrLf & vbCrLf & ex.StackTrace & Chr(13) & sErrDescription & vbCrLf & vbCrLf & "Press Control + C to copy this error report", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Business Management System - Unexepected Error Ref: " & sAuditID)
        End If

    Finally
        ' CleanUp

    End Try

End Sub

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 [ http://blog.lavablast.com/post/2007/11/29/The-Mysterious-Parameter-Is-Not-Valid-Exception.aspx ] , 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.

Any suggestions to what is wrong?

EDIT 1 Before closing the form, I clear all the treenodes and then use Me.Close()

    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

EDIT 2 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.

imgur.com/QQ2FzFV


Solution

  • I had tried to use GC.Collect to see if it works, and surprising it did. Sadly it worked on one machine and didn't in another. Therefore, instead of calling images directly from my resources, I have stored all required images in an image list which I have attached to my treeviews. It's working like a charm.