active-directory - 创建事件时出现 ErrorIrresolvableConflict

标签 active-directory adal office365api outlook-restapi office365-restapi

我在尝试创建事件时收到很多与 ErrorIrresolvableConflict 响应代码相关的错误

Stack Trace -    at Microsoft.OData.ProxyExtensions.DataServiceContextWrapper.<SaveChangesAsync>d__5e.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 Office365CalendarProviderBL.<>c__DisplayClass7_0.<<CreateCalendarEvent>b__0>d.MoveNext() - Inner Exception - Microsoft.OData.Client.DataServiceRequestException: An error occurred while processing this request. ---> Microsoft.OData.Client.DataServiceClientException: {"error":{"code":"ErrorIrresolvableConflict","message":"The send or update operation could not be performed because the change key passed in the request does not match the current change key for the item."}}
   --- End of inner exception stack trace ---
   at Microsoft.OData.Client.SaveResult.HandleResponse()
   at Microsoft.OData.Client.BaseSaveResult.EndRequest()
   at Microsoft.OData.Client.DataServiceContext.EndSaveChanges(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- 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.OData.ProxyExtensions.DataServiceContextWrapper.<SaveChangesAsync>d__5e.MoveNext()

我收到此异常消息 - 无法执行发送或更新操作,因为请求中传递的更改键与项目的当前更改键不匹配。

  1. 请解释什么是更改 key 及其工作原理?
  2. 我从昨天才得到这些异常并且没有更改任何代码。我最后是否需要更新任何内容或是否遗漏了任何内容?

我正在使用 V1 DLL - https://api.office.com/discovery/v1.0/me/ 代理扩展版本 - 23

代码:-

// In this method, we are populating event properties later used to create event on calendar. Please verify if I am missing any important property here
private Event CreateCalEventObj(CalendarMeetingBL meeting, string location, meetingAdditionalDataBL data)
{
    Event calEvent = new Event();
    try
    {
        calEvent.Subject = WEB.HttpUtility.HtmlDecode(meeting.MeetingName);
        calEvent.ShowAs = FreeBusyStatus.Busy;
        if (meeting.EventAlarmInMinutes == -1)
            meeting.EventAlarmInMinutes = null;
        calEvent.Reminder = meeting.EventAlarmInMinutes;
        calEvent.Start = meeting.StartTime;
        calEvent.End = meeting.EndTime;
        calEvent.StartTimeZone = meeting.TimeZoneString;
        calEvent.EndTimeZone = meeting.TimeZoneString;

        if (!string.IsNullOrEmpty(location) && location.Length <= 500)
        {
            calEvent.Location = new Microsoft.Office365.OutlookServices.Location()
            {
                DisplayName = CommonBL.FixLineBreakForGooglelocation(WEB.HttpUtility.HtmlDecode(location.Replace("\n", " ")))
            };
        }
        else if (!string.IsNullOrEmpty(data.Phone))
        {
            calEvent.Location = new Microsoft.Office365.OutlookServices.Location()
            {
                DisplayName = "Phone: " + CommonBL.FixLineBreakForGooglelocation(WEB.HttpUtility.HtmlDecode(data.Phone))
            };
        }
        else if (!string.IsNullOrEmpty(data.MobileNumber))
        {
            calEvent.Location = new Microsoft.Office365.OutlookServices.Location()
            {
                DisplayName = "Mobile: " + CommonBL.FixLineBreakForGooglelocation(WEB.HttpUtility.HtmlDecode(data.MobileNumber))
            };
        }
        calEvent.Body = new ItemBody()
        {
            Content = CommonBL.RevertLineBreakPlaceHolder((WEB.HttpUtility.HtmlDecode(meeting.MeetingDetails.Replace(@"\\\", "\\"))))
        };
    }
    catch (Exception ex)
    {
        BLFactory.CurrentInstance.LoggingBLObj.InsertLog("Insert logging here");
        calEvent = null;
    }
    return calEvent;
}

// In this method we are creating event on calendar.
private string CreateCalendarEvent(CalendarMeetingBL meeting, List<ParticipantBL> invitees, string username, string calendarId, OutlookServicesClient service, string location, meetingAdditionalDataBL data, string meetingId = "-1")
{
    var taskCreateMeeting = Task<string>.Run(
            async () =>
            {
                Event calEvent = CreateCalEventObj(meeting, location, data);
                if (calEvent != null)
                {
                    try
                    {
                        //Add invitees to the event
                        foreach (ParticipantBL inviteeItem in invitees)
                        {
                            if (!inviteeItem.IsAdditional)
                            {
                                calEvent.Attendees.Add(new Attendee()
                                {
                                    EmailAddress = new EmailAddress()
                                    {
                                        Address = inviteeItem.Email.Replace("&#39;", "'"),
                                        Name = inviteeItem.Name
                                    },
                                    Type = AttendeeType.Required,
                                    Status = new ResponseStatus()
                                    {
                                        Response = ResponseType.Accepted,
                                        Time = DateTime.Now
                                    }
                                });
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        BLFactory.CurrentInstance.LoggingBLObj.InsertLog(meeting.MeetingId, username, "Locally User ID is Meeting id AND email is username - Scheduling Logging Exception 3 - Stack Trace - " + ex.StackTrace + " - Inner Exception - " + ex.InnerException + " - meetingObjValues - " + meetingObjValues + " - meetingAdditionalDataObjValues - " + meetingAdditionalDataObjValues + " -  username - " + username + " - calendarId - " + calendarId + " - location - " + location + " - meetingId - " + meetingId, meeting.MeetingId);
                        return "-1";
                    }

                    try
                    {

                        var providerDefault = (String.IsNullOrEmpty(calendarId) ? service.Me.Events : service.Me.Calendars[calendarId].Events);
                        await providerDefault.AddEventAsync(calEvent);          // We are getting Exception here but Event is created in calendar                     
                        return calEvent.Id;                                     // Event object is not updated after exception
                    }
                    catch (Exception ex)
                    {
                        BLFactory.CurrentInstance.LoggingBLObj.InsertLog("Insert exception logging here");
                        return "-1";
                    }
                }
                else
                    return "-1";
            }
        );
    Task.WaitAll(taskCreateMeeting);
    string id = taskCreateMeeting.Result;
    return id;
}

我们得到的异常是 Microsoft.OData.Client.DataServiceRequestException 类型的,但它没有被专用的 catch block 捕获

                catch (Microsoft.OData.Client.DataServiceRequestException ex)
                {
                    BLFactory.CurrentInstance.LoggingBLObj.InsertLog("Insert logging here");
                    return "-1";
                }

如果有其他需要请告诉我 提前致谢。

最佳答案

这与 OData 没有直接关系 - 我们在 EWS 中看到了同样的事情。我们刚刚在 Exchange 代码中发现了导致此问题的潜在竞争条件,我们的一位开发人员刚刚检查了此问题的修复程序。因此,它应该很快就会开始投入生产。

您的代码没有任何问题会导致新项目出现这种情况。

关于active-directory - 创建事件时出现 ErrorIrresolvableConflict,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38102586/

相关文章:

c# 如何使用 Microsoft Graph API 获取 Office 365 用户照片

office365 - 如何通过 Microsoft Graph API 检索 itemAttachment 的内容

javascript - 为什么在本地引用时 office.js 不起作用?

c# - 更改密码 Windows AD C#

azure - 来自 SharePoint Online 的外部 REST 服务身份验证

owin - Microsoft.Owin.Security.OpenIdConnect 与 Azure Active Directory 身份验证票证生命周期

c# - 从 Azure AD 检索 RBAC 的用户组成员身份

Python+LDAP+SSL

azure - 权限不在有效列表中 : 'authority' is not in the list of valid addresses

google-app-engine - 云应用程序和单点登录(AD 集成)