Skip to content

'GetAsync' throw 'System.Text.Json.JsonReaderException' while trying to read mails from mailbox folders #2877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kashti3 opened this issue Mar 26, 2025 · 2 comments
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience

Comments

@kashti3
Copy link

kashti3 commented Mar 26, 2025

Describe the bug

Hi,

Graph SDK: NuGet "Microsoft.Graph" Version="5.73.0"
C# (dotnet 8)

I`m getting 'System.Text.Json.JsonReaderException' exception.

This exception is not being thrown consistently.

This is a snipped code of the Graph SDK useage:
rGraphClient .Users[mUser.Id] .MailFolders[iFolder.Id] .Messages .GetAsync(iConfig => { iConfig.QueryParameters.Select = [ "from", "receivedDateTime", "createdDateTime", "subject", "id", "hasAttachments", "body", "attachments" ]; iConfig.QueryParameters.Expand = ["attachments"]; iConfig.QueryParameters.Filter = iFilter; iConfig.QueryParameters.Orderby = ["receivedDateTime DESC"]; iConfig.QueryParameters.Top = rOffice365Settings.MailsCountToRead; iConfig.Headers.Add("Prefer", $"outlook.body-content-type=\"{rOffice365Settings.PreferredContentType}\""); iConfig.Headers.Add("Accept-Language", rOffice365Settings.AcceptLanguage); }, cancellationToken: iCancellationToken).ConfigureAwait(false);

The mail box language is in Espanol (Costa Rica) so I tried to play with the settings but it did not helped.

  • Reduce mails fetch count.
  • Changed AcceptLanguage for both English and Spanish.

When:
AcceptLanguage: en-US,
PreferredContentType: text,
mailsCountToReadPerIteration: 10

I got:
Error from System.Text.Json: System.Text.Json.JsonReaderException: 'e' is invalid after a value. Expected either ',', '}', or ']'. LineNumber: 0 | BytePositionInLine: 7464595. at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes)
at System.Text.Json.Utf8JsonReader.ConsumeNextToken(Byte marker)
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.JsonDocument.Parse(ReadOnlySpan1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack) at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter)
at System.Text.Json.JsonDocument.ParseAsyncCore(Stream utf8Json, JsonDocumentOptions options, CancellationToken cancellationToken)
at Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory.GetRootParseNodeAsync(String contentType, Stream content, CancellationToken cancellationToken)
at Microsoft.Kiota.Abstractions.Serialization.ParseNodeProxyFactory.GetRootParseNodeAsync(String contentType, Stream content, CancellationToken cancellationToken)
at Microsoft.Kiota.Abstractions.Serialization.ParseNodeFactoryRegistry.GetRootParseNodeAsync(String contentType, Stream content, CancellationToken cancellationToken)
at Microsoft.Kiota.Abstractions.Serialization.ParseNodeProxyFactory.GetRootParseNodeAsync(String contentType, Stream content, CancellationToken cancellationToken)
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.GetRootParseNodeAsync(HttpResponseMessage response, CancellationToken cancellationToken)
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken)
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken)
at Microsoft.Graph.Users.Item.MailFolders.Item.Messages.MessagesRequestBuilder.GetAsync(Action1 requestConfiguration, CancellationToken cancellationToken)

When:
AcceptLanguage: es-ES
PreferredContentType: text
MailsCountToRead: 10

I got:

Error from System.Text.Json: System.Text.Json.JsonReaderException: Expected depth to be zero at the end of the JSON payload. There is an open JSON object or array that should be closed. LineNumber: 0 | BytePositionInLine: 361.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack)
   at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter)
   at System.Text.Json.JsonDocument.ParseAsyncCore(Stream utf8Json, JsonDocumentOptions options, CancellationToken cancellationToken)
   at Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory.GetRootParseNodeAsync(String contentType, Stream content, CancellationToken cancellationToken)
   at Microsoft.Kiota.Abstractions.Serialization.ParseNodeProxyFactory.GetRootParseNodeAsync(String contentType, Stream content, CancellationToken cancellationToken)
   at Microsoft.Kiota.Abstractions.Serialization.ParseNodeFactoryRegistry.GetRootParseNodeAsync(String contentType, Stream content, CancellationToken cancellationToken)
   at Microsoft.Kiota.Abstractions.Serialization.ParseNodeProxyFactory.GetRootParseNodeAsync(String contentType, Stream content, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.GetRootParseNodeAsync(HttpResponseMessage response, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Graph.Users.Item.MailFolders.Item.Messages.MessagesRequestBuilder.GetAsync(Action`1 requestConfiguration, CancellationToken cancellationToken)

Please advice how to continue.

Expected behavior

Enable to read emails

How to reproduce

I`m not sure but maybe set the mailbox language to Spanish

SDK Version

5.73.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
@kashti3 kashti3 added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Mar 26, 2025
@MartinM85
Copy link
Contributor

I think that PreferredContentType must be text not txt

@kashti3
Copy link
Author

kashti3 commented Mar 27, 2025

I think that PreferredContentType must be text not txt

You are right but this was a typo on the issue when run my application this issue happen to me when it was 'text'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

2 participants