我也在GitHub上问过这个问题。此代码引发异常:
// Add the event
Event createdEvent = await _graphClient.Me.Calendars[oSettings.CalendarID].Events.PostAsync(new Event
{
Subject = oEvent.GetSubject(),
Body = body,
Start = startTime,
End = endTime,
IsAllDay = oEvent.IsAllDayEvent(),
IsReminderOn = bSetReminder,
ReminderMinutesBeforeStart = bSetReminder ? iReminderMinutes : (int?)null,
Location = location,
SingleValueExtendedProperties = extendedProperties,
Sensitivity = oSettings.SetCalendarPrivate ? Sensitivity.Private : Sensitivity.Normal
});
我认为问题应该是这行代码:
ReminderMinutesBeforeStart = bSetReminder ? iReminderMinutes : (int?)null
因为,如果bSetReminder
是true
,那么我不会得到异常。bSetReminder
为false
时发生异常。例外情况:
<LogEntry Date="2023-05-22 16:30:40" Severity="Exception" Source="OutlookCalIFConsole.Outlook+<AddEventToCalendar>d__18.MoveNext" ThreadId="6">
<Exception Type="Microsoft.Graph.Models.ODataErrors.ODataError" Source="Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter+<ThrowIfFailedResponse>d__28.MoveNext">
<Message>Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown.</Message>
<StackTrace> at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.<ThrowIfFailedResponse>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.<SendAsync>d__20`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.<SendAsync>d__20`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.Me.Calendars.Item.Events.EventsRequestBuilder.<PostAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at OutlookCalIFConsole.Outlook.<AddEventToCalendar>d__18.MoveNext()</StackTrace>
</Exception>
</LogEntry>
请看linked question,它有一个答案。我相信这曾经是有效的,但在最近的Graph版本中,它现在失败了。欢迎咨询。
1条答案
按热度按时间jdg4fx2g1#
如果
bSetReminder
是false
,则将ReminderMinutesBeforeStart
设置为0
,而不是null
。