以下は完全な機能ですが、これはエラーの原因であると私が信じているコードの領域です。
編集:関数をステップスルーした後、「taskrequestItem.GetAssociatedTask(False)」に設定した後でも、ループの周りの2回目は何もないように見えます。したがって、ループのそのインスタンスでは、最初にtaskItemが参照されます。 。taskitem.categories = "TTD"の場合、例外がスローされます。ただし、ifステートメントに「ANDtaskItem IsNot Nothing」の条件を追加しても、この例外が発生します。
If (TypeOf (resultItem) Is Outlook._TaskRequestItem) Then
counter += 1
taskrequestItem = resultItem
taskItem = taskrequestItem.GetAssociatedTask(False)
'taskItem.PercentComplete = 10
'If Not (taskItem.Status = Outlook.OlTaskStatus.olTaskComplete) Then
'strBuilder.AppendLine("#" + counter.ToString() + _
'" 2duedate: " + )
If taskItem.Categories = "TTD" Then
TTDcounter += 1
Dim listarray() As String = {taskItem.Delegator, taskItem.Subject, taskItem.DueDate, stripEstComp(taskItem.Body.ToString())}
taskPaneControl3.ListView2.Items.Add("New").SubItems.AddRange(listarray)
End If
End If
'End If
Marshal.ReleaseComObject(resultItem)
resultItem = folderItems.FindNext()
Loop Until IsNothing(resultItem)
各taskrequestitemから関連するtaskitemをフェッチする部分を追加した後、エラーがポップアップし始めました。
Private Sub GetTaskRequests(objApp As Microsoft.Office.Interop.Outlook.Application)
Dim folder As Outlook.Folder = _
TryCast(Application.Session.Folders(email).Folders("Inbox"), Outlook.Folder)
Dim searchCriteria As String = "[MessageClass] = 'IPM.TaskRequest'"
Dim strBuilder As StringBuilder = Nothing
Dim counter As Integer = 0
Dim taskrequestItem As Outlook.TaskRequestItem = Nothing
Dim taskItem As Outlook.TaskItem = Nothing
Dim folderItems As Outlook.Items = Nothing
Dim resultItem As Object = Nothing
Dim TTDcounter As Integer = 0
Try
folderItems = folder.Items
folderItems.IncludeRecurrences = True
If (folderItems.Count > 0) Then
resultItem = folderItems.Find(searchCriteria)
If Not IsNothing(resultItem) Then
strBuilder = New StringBuilder()
Do
If (TypeOf (resultItem) Is Outlook._TaskRequestItem) Then
counter += 1
taskrequestItem = resultItem
taskItem = taskrequestItem.GetAssociatedTask(False)
'taskItem.PercentComplete = 10
'If Not (taskItem.Status = Outlook.OlTaskStatus.olTaskComplete) Then
'strBuilder.AppendLine("#" + counter.ToString() + _
'" 2duedate: " + )
'If taskItem.Categories = "TTD" Then
TTDcounter += 1
Dim listarray() As String = {taskItem.Delegator, taskItem.Subject, taskItem.DueDate, stripEstComp(taskItem.Body.ToString())}
taskPaneControl3.ListView2.Items.Add("New").SubItems.AddRange(listarray)
'End If
End If
'End If
Marshal.ReleaseComObject(resultItem)
resultItem = folderItems.FindNext()
Loop Until IsNothing(resultItem)
End If
End If
If Not IsNothing(strBuilder) Then
Debug.WriteLine(strBuilder.ToString())
Else
Debug.WriteLine("There is no match in the " + _
folder.Name + " folder.")
End If
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
Debug.WriteLine("gettaskrequest")
Finally
If Not IsNothing(folderItems) Then Marshal.ReleaseComObject(folderItems)
End Try
End Sub