Hi there,
This is the section of code that is giving me an error:
The error is as follows:
"Unable to cast object of type 'System.ComponentModel.AsyncOperation' to type 'UploadBitsState'"
The thing is, it works fine on the x64 Windows 7 machine, but when running on x86 Windows XP is errors.
All of the BackgroundWorkers I'm using/linking are as follows. Any help would be greatly appreciated:
This is the section of code that is giving me an error:
vb Code:
Private Sub bgw_UploadZip_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw_UploadZip.DoWork 'Uploads complete .zip file via FTP to client location My.Computer.Network.UploadFile(System.IO.Path.GetTempPath & ZipFilename & ".zip", "ftp://domain.com" & ZipFilename & ".zip", "user", "pass", FileIO.UIOption.AllDialogs, 100, FileIO.UICancelOption.DoNothing) End Sub
The error is as follows:
"Unable to cast object of type 'System.ComponentModel.AsyncOperation' to type 'UploadBitsState'"
The thing is, it works fine on the x64 Windows 7 machine, but when running on x86 Windows XP is errors.
All of the BackgroundWorkers I'm using/linking are as follows. Any help would be greatly appreciated:
vb Code:
Private Sub bgw_CopyDocs_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw_CopyDocs.DoWork MsgBox("Copy") 'Copies all files into a temporary folder to be zipped For Each row As DataGridViewRow In frm_TMDocumentReview.dgv_TMDocumentReview.Rows Try My.Computer.FileSystem.CopyFile(CurrentProjectsLocation & "\" & _ tbx_Client.Text & "\" & _ tbx_JobNo.Text & " - " & tbx_JobTitle.Text & "\" & _ row.Cells("Category = DC Level 4").Value.ToString & "\" & _ row.Cells("Discipline = DC Level 5").Value.ToString & "\" & _ row.Cells("Document Type 1 = DC Level 6").Value.ToString & "\" & _ row.Cells("Document Type 2 = DC Level 7").Value.ToString & "\" & _ row.Cells("Filename").Value.ToString & _ row.Cells("File Extension").Value.ToString, System.IO.Path.GetTempPath & TempTMID & "\" & row.Cells("Filename").Value.ToString & row.Cells("File Extension").Value.ToString) Catch ex As Exception MsgBox("File does not exist:" & vbNewLine _ & vbNewLine _ & ex.ToString) End Try Next MsgBox("Copy complete") End Sub Private Sub bgw_CopyDocs_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw_CopyDocs.RunWorkerCompleted If e.Cancelled = True Then ElseIf e.Error IsNot Nothing Then MsgBox("(Test4) - Error: " & e.Error.Message) Else 'Starts backgroundworker to create zipfile If bgw_CreateZip.IsBusy <> True Then bgw_CreateZip.RunWorkerAsync() End If End If End Sub Private Sub bgw_CreateZip_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw_CreateZip.DoWork Try 'Process.Start("explorer.exe", System.IO.Path.GetTempPath & TempTMID) 'The following data represents an empty zip file . Dim startBuffer() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, _ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 'Data for an empty zip file . FileIO.FileSystem.WriteAllBytes(System.IO.Path.GetTempPath & ZipFilename & ".zip", startBuffer, False) 'Declare new shell class 'Dim sc As New Shell32.Shell() Dim ShellAppType As Type = Type.GetTypeFromProgID("Shell.Application") Dim sc As Object = Activator.CreateInstance(ShellAppType) 'Declare the folder which contains the files you want to zip . Dim input As Shell32.Folder = sc.NameSpace(System.IO.Path.GetTempPath & TempTMID) 'Declare your created empty zip file as folder . Dim output As Shell32.Folder = sc.NameSpace(System.IO.Path.GetTempPath & ZipFilename & ".zip") 'Copy the files into the empty zip file using the CopyHere command . output.CopyHere(input.Items, 4) Dim worker As BackgroundWorker = CType(sender, BackgroundWorker) worker.ReportProgress(10) Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub Private Sub bgw_CreateZip_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw_CreateZip.RunWorkerCompleted If e.Cancelled = True Then ElseIf e.Error IsNot Nothing Then MsgBox("(Test3) - Error: " & e.Error.Message) Else Dim ConfirmUpload = MsgBox("The documents will now be uploaded.", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Upload Transmittal Documents") If ConfirmUpload = DialogResult.Cancel Then Exit Sub ElseIf ConfirmUpload = DialogResult.OK Then 'Starts backgroundworker to upload zipped files If bgw_UploadZip.IsBusy <> True Then bgw_UploadZip.RunWorkerAsync() End If End If End If End Sub Private Sub bgw_UploadZip_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw_UploadZip.DoWork 'Uploads complete .zip file via FTP to client location My.Computer.Network.UploadFile(System.IO.Path.GetTempPath & ZipFilename & ".zip", "ftp://domain.com" & ZipFilename & ".zip", "user", "Tpass", FileIO.UIOption.AllDialogs, 100, FileIO.UICancelOption.DoNothing) End Sub Private Sub bgw_UploadZip_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw_UploadZip.RunWorkerCompleted If e.Cancelled = True Then ElseIf e.Error IsNot Nothing Then MsgBox("(Test2) - Error: " & e.Error.Message) Else MsgBox("The documents within this transmittal have been uploaded successfully." & vbNewLine _ & vbNewLine _ & ZipFilename & ".zip", MsgBoxStyle.Information, "Documentation Upload") 'Starts backgroundworker to prepare email If bgw_PrepEmail.IsBusy <> True Then bgw_PrepEmail.RunWorkerAsync() End If End If End Sub Private Sub bgw_PrepEmail_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw_PrepEmail.DoWork Dim olApp As Object olApp = CreateObject("Outlook.Application") If olApp IsNot Nothing Then Dim olEmail As New Object olEmail = olApp.CreateItem(0) olEmail.To = Transmittal_SelectedRecipients_Emails olEmail.Subject = "Transmittal: " & Transmittal_TMNo & " (" & Transmittal_JobNo & " - " & Transmittal_JobTitle & ")" olEmail.HTMLBody = "<p style = 'font-family: Calibri; font-size: 11pt;'>Please find document transmittal " & Transmittal_TMNo & " attached.<br><br>" & _ "Use the link below to download the documents in this transmittal.<br>" & _ "<a href='http://www.domain.com/" & ZipFilename & ".zip'>Click to download</a></p>" olEmail.Attachments.Add(NewDocument_Location & ".pdf") olEmail.Display(True) End If End Sub Private Sub bgw_PrepEmail_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw_PrepEmail.RunWorkerCompleted GenerateDocNo() cbx_TMDesc.Text = "" tbx_Comments.Text = "" cbx_Company.Text = "" cbx_TMDesc.Select() ResetVariablesTM() dgv_TMDocuments.DataSource = Nothing End Sub