1

I'm using Microsoft Graph .NET SDK to update outlook events. Following code successfully updates the Subject, and Body attributes of an event. But when I try to update the Start and/or End dates of the the event (that are of the dateTimeTimeZone type) I get the error shown below:

Question: What may be the cause of the error, and how can we resolve it? Please note that the event has valid local Start and End dates as 8/21/2020 11:00AM and 8/21/2020 11:30AM respectively. Actually, in the debug mode, VS2019 is showing: Start.get returns null

Screenshot of the error:

enter image description here

Code:

  1. The above error occurs if I uncomment the line Start = { DateTime = "2020-08-20T08:30:00.0000000", TimeZone = "UTC" } below.
  2. The values of authProvider and "{id}" varibles are not that relevant to the error as the code with the real values works fine without the line Start =.... of the code.

...

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var @event = new Event
{
    Subject = "Test subject",
    Body= new ItemBody { Content = "Test body content"}
    //Start = { DateTime = "2020-08-20T08:30:00.0000000", TimeZone = "UTC" }
};

await graphClient.Me.Events["{id}"]
    .Request()
    .UpdateAsync(@event);
nam
  • 21,967
  • 37
  • 158
  • 332

2 Answers2

1

You need something like this instead because of the object type being used in the property

            var @event = new Event
        {
            Subject = "Test subject",
            Body = new ItemBody { Content = "Test body content" },
            Start = new DateTimeTimeZone {  DateTime = "2020-08-20T08:30:00.0000000", TimeZone = "UTC" } 
        };
Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • Thanks for pointing out me not using the object type in the property. That actually was the issue. – nam Aug 20 '20 at 13:54
  • I've a relevant issue [here](https://stackoverflow.com/q/63625544/1232087) if you have a time to suggest/comment on it. Thank you. – nam Aug 27 '20 at 23:46
1

You need to add date in below format. Hope it will solve your issue.

var @event = new Event
    {
        Subject = "Test subject",
        Body = new ItemBody { Content = "Test body content" },
        Start = new DateTimeTimeZone {  DateTime = "2020-08-20T08:30:00.0000000", TimeZone = "GMT Standard Time" } 
    };
Rajeev Kumar
  • 371
  • 2
  • 9
  • I do need to use `UTC`. The issue was that I was not using object type in the property. Thank you for trying to help. Much appreciated. An upvote from me. – nam Aug 20 '20 at 13:56