Hello
I have written some code to copy files between the guest and the local system.
I read the directories within the guest with the methode ListDirectoryInGuest. I initiate it when I expand a directory (the node within the treelist). The first two times I'm able to expand the node and receive the results of the new directory level. Mostly the third time the application will crash with the following message:
Runtime Error
This application has requested the runtime to terminate it in an unusual way.
This Problem occures only on some systems but if it is a problem on a system it appears all the time.
The error can't be tracked with the debugger (or I don't know how?)
As it appears the result of the directory list is returned and processed, the application just crashes after processing the result.
Below is the function I use to retrieve the directories and files...
Does anyone have an idea what causes this crash? It seems to be related with the VIX API
Regards
Manfred
Private Function RetrieveFiles(ByVal path As String, ByVal parentnodeID As Integer, ByVal ForGrid As Boolean) As Boolean
Try
GuestResults.Clear()
If CheckConnectState() Then
PathToRetrieve = path
ParentNodeID_Used = parentnodeID
Dim FlagList() As Integer = {Constants.VIX_PROPERTY_JOB_RESULT_ITEM_NAME, Constants.VIX_PROPERTY_JOB_RESULT_FILE_FLAGS, Constants.VIX_PROPERTY_JOB_RESULT_FILE_MOD_TIME}
Dim numResults As Integer
job = Interfacevm.ListDirectoryInGuest(path, 0, Nothing)
vix_status = job.WaitWithoutResults
If VixLib.ErrorIndicatesFailure(vix_status) Then
Dim VixException As New Exception("Retrieve directories and files failed '" & VM_VMXPath & "' failed with exception '" & VixLib.GetErrorText(vix_status, Nothing) & "'")
XtraMessageBox.Show(VixException.Message, " Can't Retrieve Guest Files ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
VixException = Nothing
Return False
End If
If DebugGuestFiles Then Console.WriteLine(GetCurrentMethod.DeclaringType.Name & " " & GetCurrentMethod().Name & " Guest Files retrieved")
numResults = job.GetNumProperties(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_ITEM_NAME)
Dim node As TreeListNode
' If ForGrid Then tlGuest.BeginUnboundLoad()
For i As Integer = 0 To numResults - 1
Dim results As Object
vix_status = job.GetNthProperties(i, FlagList, results)
If VixLib.ErrorIndicatesFailure(vix_status) Then
Dim VixException As New Exception("List Files '" & VM_VMXPath & "' failed with exception '" & VixLib.GetErrorText(vix_status, Nothing) & "'")
XtraMessageBox.Show(VixException.Message, " Can't Retrieve Guest Files ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
VixException = Nothing
Else
Select Case results(1)
Case Constants.VIX_FILE_ATTRIBUTES_SYMLINK
If ForGrid Then
Addnode(path & FilesystemSeparator & results(0), results(0), results(2), parentnodeID, 4, "file")
'node = tlGuest.AppendNode(New Object() {path & FilesystemSeparator & results(0), results(0), ConvertDateEpoche(results(2)), "file"}, parentnodeID)
'node.ImageIndex = 4
'node.SelectImageIndex = 4
Else
Dim res As New GuestItem
res.isDirectory = False
res.ShortName = results(0)
res.Fullpath = path & FilesystemSeparator & results(0)
GuestResults.Add(res)
res = Nothing
End If
'Console.WriteLine("Link:" & results(0) & " Modified:" & ConvertDateEpoche(results(2)) & " " & vbLf)
Case Constants.VIX_FILE_ATTRIBUTES_DIRECTORY
If ForGrid Then
Addnode(path & FilesystemSeparator & results(0), results(0), results(2), parentnodeID, 0, "folder")
'node = tlGuest.AppendNode(New Object() {path & FilesystemSeparator & results(0), results(0), ConvertDateEpoche(results(2)), "folder"}, parentnodeID)
'node.ImageIndex = 0
'node.SelectImageIndex = 0
'node.HasChildren = True
Else
Dim res As New GuestItem
res.isDirectory = True
res.ShortName = results(0)
res.Fullpath = path & FilesystemSeparator & results(0)
GuestResults.Add(res)
res = Nothing
End If
'Console.WriteLine("Directory:" & results(0) & " Modified:" & ConvertDateEpoche(results(2)) & " " & vbLf)
Case Else
If ForGrid Then
'Retrieve Extension
' Dim sExtension As String = results(0).Substring(InStrRev(results(0), "."))
'If results(0) = "acpid" Then
' Console.WriteLine()
'End If
Dim sExtension As String = System.IO.Path.GetExtension(results(0))
Dim index As Integer = -1
If sExtension <> "" Then
index = imageList1.Images.IndexOfKey(sExtension)
End If
If index = -1 Then 'Not found
If sExtension = "" Then
index = 2
Else
Dim ic As Icon = retieveIcon.GetDefaultIcon(results(0), 1)
imageList1.Images.Add(sExtension, ic)
index = imageList1.Images.IndexOfKey(sExtension)
ic = Nothing
End If
End If
Addnode(path & FilesystemSeparator & results(0), results(0), results(2), parentnodeID, index, "file")
'node = tlGuest.AppendNode(New Object() {path & FilesystemSeparator & results(0), results(0), ConvertDateEpoche(results(2)), "file"}, parentnodeID)
'node.SelectImageIndex = index
'node.ImageIndex = index
index = Nothing
sExtension = Nothing
Else
Dim res As New GuestItem
res.isDirectory = False
res.ShortName = results(0)
res.Fullpath = path & FilesystemSeparator & results(0)
GuestResults.Add(res)
res = Nothing
End If
End Select
End If
results = Nothing
Next
If DebugGuestFiles Then Console.WriteLine(GetCurrentMethod.DeclaringType.Name & " " & GetCurrentMethod().Name & " Guest Files Added to grid")
If ForGrid Then
' tlGuest.EndUnboundLoad()
SortTreelist()
End If
FlagList = Nothing
numResults = Nothing
node = Nothing
job = Nothing
If DebugGuestFiles Then Console.WriteLine(GetCurrentMethod.DeclaringType.Name & " " & GetCurrentMethod().Name & " Guest Files retrieve completed")
Return (True)
Else
Return False
End If
Catch ex As Exception
Return False
End Function