This project is read-only.

RAS.Connect error


I am seeing some strange behavior from the RAPI.Connect call. My application is designed to pull XML files from a cradled device.
I start my application, a WinForm executable
I start my upload menu item and the device is cradled then the RAPI.Connect() works fine.
If I leave my upload form running and uncradle and re-cradle the device the RAPI.Connect() works fine.
If, however, I close my upload form and reopen it then I get an error from the RAPI.Connect() call - "Value does not fall within the expected range"
If I go ahead and close my application entirely and reopen it and then reopen the upload form then all is well with the RAPI.Connect.
I am checking if the device is present before attempting to connect and this is not failing. Also, I am reinstantiating the RAPI object as NEW right before I attempt to use it. I am disconnecting, and disposing the object as well.
Can someone please clue me in as to what is happening with the connection process flow.
Code Snippet: This is the code that exhibits the error on statement objRAPI.Connect(). It is executed when the user clicks a button on the form to load the XML from the device.
Public Sub XFER_UPLOAD()
    Dim MethodName As String = "XFER_UPLOAD"

        blnXFERUploaded = False
        blnStopUpload = True

        Dim objRAPI As New RAPI()
        If objRAPI.DevicePresent Then
            blnBadComm = True
            blnBadComm = False
            If Not blnBadComm Then
                Dim tmpFilelist As FileList
                Dim tmpFileInfo As FileInformation

                tmpFilelist = objRAPI.EnumFiles("\*XFER.XML")
                If Not tmpFilelist Is Nothing Then
                    For Each tmpFileInfo In tmpFilelist
                        strLocalFileName = strRecvPath & "\" & _
                                tmpFileInfo.FileName.ToString.ToUpper.Replace(".XML", "") & _
                        strRemoteFileName = "\" & tmpFileInfo.FileName

                        If objRAPI.DeviceFileExists(strRemoteFileName) Then
                            objRAPI.CopyFileFromDevice(strLocalFileName, strRemoteFileName)
                            blnRECVUploaded = True
                        End If
                    Call COPY_XFER_TO_NETWORK()
                    blnStopUpload = False

                End If

                If blnUploadAll = False Then
                    If blnRECVUploaded = True Then
                        MessageBox.Show("Transfer/Picking files successfully uploaded.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
                        MessageBox.Show("No transfer/picking files to upload.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
                    End If
                End If
            End If
        End If
        objRAPI = Nothing
    Catch exp As Exception
        If exp.Message.ToString.ToUpper = "UNABLE TO LOAD DLL (RAPI.DLL)." Then
            MessageBox.Show("ActiveSync is not installed on this machine.  Please install ActiveSync or upload the files on a machine which has ActiveSync installed.", _
                            "Error", _
                            MessageBoxButtons.OK, _
                            MessageBoxIcon.Warning, _
        ElseIf exp.Message.ToString.ToUpper = "VALUE DOES NOT FALL WITHIN THE EXPECTED RANGE." Then
            Call Psi_ErrorHandler.LogError(ClassName, MethodName, exp)
        End If
    End Try

End Sub