microsoftgraph / msgraph-sdk-dotnet

Microsoft Graph Client Library for .NET!
https://graph.microsoft.com
Other
703 stars 249 forks source link

Getting email with open type extension expanded fails on Json deserialization exception #1158

Closed Jurysko closed 3 years ago

Jurysko commented 3 years ago

Describe the bug Sample from https://docs.microsoft.com/en-us/graph/api/opentypeextension-get?view=graph-rest-1.0&tabs=csharp#request-3 for c# fails with Exception thrown: 'System.InvalidOperationException' in System.Text.Json.dll The requested operation requires an element of type 'Object', but the target element has type 'Array'. at System.Text.Json.JsonDocument.TryGetNamedPropertyValue(Int32 index, ReadOnlySpan`1 propertyName, JsonElement& value)

To Reproduce Steps to reproduce the behavior:

  1. Create simple setup to be able to get data as described in linked sample (initialize GraphServiceClient with app that is able to read messages, obtain user id, create message and get its id)
  2. call method from sample

Expected behavior Call succeeds and response is parsed into Message class.

Client version Microsoft.Graph 4.7.0 net5.0

Desktop (please complete the following information):

andrueastman commented 3 years ago

Hey @Jurysko,

Thanks for raising this.

Are you able to provide the sample of the response you get back by running the sample below and sharing the values of the content? This will help us understand better what could be happening in your scenario.

var messageResponse = await graphClient.Me.Messages["message-id"]
    .Request()
    .Expand("extensions($filter=id%20eq%20'Microsoft.OutlookServices.OpenTypeExtension.Com.Contoso.Referral')")
    .GetResponseAsync();

var stringResponse = await messageResponse.Content.ReadAsStringAsync();
Jurysko commented 3 years ago

Hello, Thanks for reaching me out. I don’t use app with delegated permissions, but app with app permissions. Therefore I am unable to call „.Me“ endpoint. I can create new app with delegated permissions. I called code from your sample with „Users[]“ endpoint resulting with data in attachment. Event the request that is commented out failed in my case with the same exception (I deleted all but 1 message prior to calling the request). I have tried to use different user and got the same exception.

//var messages = (await graphClient.Users[userId].Messages.Request().GetAsync());
var messageResponse = await graphClient.Users[userId].Messages[messageId]
      .Request()
      .Expand("extensions($filter=id%20eq%20'Microsoft.OutlookServices.OpenTypeExtension.Com.Contoso.Referral')")
      .GetResponseAsync();
var stringResponse = await messageResponse.Content.ReadAsStringAsync();

I have checked other development tenant and got the same problem.

Best Regards Jurysko GetResponseAsync.txt

andrueastman commented 3 years ago

Hey @Jurysko,

Thanks again for the extra information. Unfortunately, I am unable to replicate this error using your sample payload or making a similar call to graph using Microsoft.Graph v4.7.0.

Any chance you are able to give more information if you have specified a version of Microsft.Graph.Core in your csproj and/or share the contents of the csproj file?

Jurysko commented 3 years ago

Hello @andrueastman, I am attaching the whole project. If anything else could influence my weird result let me know. ExtendedMessageReadFail.zip Thank you

Jurysko commented 3 years ago

Sorry about closing this, I really shouldn't be doing 2 things simultaneously.

andrueastman commented 3 years ago

Hey @Jurysko,

Thanks again for sharing this. I am still unable to replicate the exception reported with the project. I suspect something in the payload on your side might be causing this as the project looks configured correctly.

Since you mentioned that you experience the error on this call as well,

//var messages = (await graphClient.Users[userId].Messages.Request().GetAsync());

Are you able to modify the call as below as well and share the response to help us understand where the issue could be?

var messagesResponse = (await graphClient.Users[userId].Messages.Request().GetResponseAsync());
var stringResponse = await messagesResponse.Content.ReadAsStringAsync();
Console.Out.WriteLine(stringResponse);
Jurysko commented 3 years ago

Sure, here is the output. GetMessages-GetResponseAsync.txt

andrueastman commented 3 years ago

Hey @Jurysko,

Unfortunately, I'm still unable to replicate the error and deserializing the payload you provided works without any issue on my end.

To follow up, any chance you can still replicate this with the latest 4.8.0 version of Microsoft graph package?

Jurysko commented 3 years ago

I reinstalled Visual Studio and problem disappeared. Both requests (get messages and read message with extension) are now working without issues. Sorry about raising this, I didn't expect this could fix anything since I didn't have any other problems with complex projects.

Thank you for your assistance and goodwill

andrueastman commented 3 years ago

No worries about that @Jurysko

eziante commented 2 years ago

Just to pitch in on this for people coming here in the future.

We had the same issue no matter which endpoint we were calling when using VS2022 (17.0.1). We tried on a different computer which had VS2022 (17.0.2) installed and the code worked fine. We then tried to upgrade the first machine to version 17.0.2 and the code started to work on that machine as well.

We don't know if the issue is caused by a bug in 17.0.1 or If the upgrade caused something to happen similar to a reinstall as @Jurysko did.