microsoftgraph / msgraph-beta-sdk-dotnet

The Microsoft Graph Client Beta Library for .NET supports the Microsoft Graph /beta endpoint. (preview)
Other
96 stars 32 forks source link

DateTimeOffset incorrectly serialized according to OData specification #279

Closed SirRichie closed 3 years ago

SirRichie commented 3 years ago

When trying to use the Graph API to upload a UserPfxCertificate the SDK provides the type UserPfxCertificate.

Its date-related properties are of type DateTimeOffset. However, when using above endpoint, the seralized date properties are not adhering to Edm.DateTimeOffset

This results in the Graph endpoint to return with an error, e.g.: Cannot convert the literal '14.04.2021 14:11:27 +02:00' to the expected type 'Edm.DateTimeOffset'.

After some investigation and directly querying the underlying seralizer, I noticed that the format is correct for DateTime, but not for DateTimeOffset: var request = graphService.DeviceManagement.UserPfxCertificates.Request(); Console.WriteLine(request.Client.HttpProvider.Serializer.SerializeObject(DateTime.Now)); // results in "\"2021-04-14T14:12:31.6191591+02:00\"" Console.WriteLine(request.Client.HttpProvider.Serializer.SerializeObject(new DateTimeOffset())); // "\"01.01.0001 00:00:00 \\u002B00:00\""

The latter is incorrect and leads to the specified error.

AB#8984

andrueastman commented 3 years ago

@SirRichie Thanks for raising this issue. Coudl you provide what version of the sdk are you using?

SirRichie commented 3 years ago

Hi, sorry I forgot to mention that. Version is 4.0.0-preview

andrueastman commented 3 years ago

Any chance you could try the latest update? That is 4.0.1-preview.

SirRichie commented 3 years ago

This seems to work. Sorry for the confusion I thought I tested with the latest version but I guess I did not.

andrueastman commented 3 years ago

No worries about that. Thanks for trying out the new preview!