Skip to content
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

Failed to get message with JsonReaderException, when it is a forwarding appointment #2000

Closed
bagdxk opened this issue Jul 6, 2023 · 7 comments · Fixed by microsoft/kiota-http-dotnet#123
Labels

Comments

@bagdxk
Copy link

bagdxk commented Jul 6, 2023

Describe the bug
Calling below function, if the message is a forwarding appointment.

_client.Me.Messages[msgId.UrlEncode()].GetAsync()

And get below error

       ---> System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
         at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
         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.Parse(Stream utf8Json, JsonDocumentOptions options)
         at Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory.GetRootParseNode(String contentType, Stream content)
         at Microsoft.Kiota.Abstractions.Serialization.ParseNodeProxyFactory.GetRootParseNode(String contentType, Stream content)
         at Microsoft.Kiota.Abstractions.Serialization.ParseNodeFactoryRegistry.GetRootParseNode(String contentType, Stream content)
         at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.GetRootParseNode(HttpResponseMessage response)
         at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
         at Microsoft.Graph.Me.Messages.Item.MessageItemRequestBuilder.GetAsync(Action`1 requestConfiguration, CancellationToken cancellationToken)

To Reproduce
I am developing an outlook add-in, which call my web API to process mail messages.

Steps to reproduce the behavior:

  1. Send an appointment to some one.
  2. Open the appointment and forward to someone else.
  3. The outlook add-in is triggered and calls the web API, in the web API it reads message by graph API
  4. And get above exception

Expected behavior
I expect the application can read the message, no exception.

Desktop (please complete the following information):

  • OS: [Windows 10]
  • Browser [Outlook, or Edge]
  • Version [Mirsoft.Graph 5.9.0 or 5.16.0]
@ghost ghost added the Needs: Triage label Jul 6, 2023
@andrueastman
Copy link
Member

Thanks for raising this @bagdxk

Any chance the result id different if you do not encode the message id?(as the SDK does handle encoding, double encoding may occur)

_client.Me.Messages[msgId].GetAsync()

@bagdxk
Copy link
Author

bagdxk commented Jul 6, 2023

I tried to remove the UrlEncode and got same error.
BTW UrlEncode is like below, so it doesn't change the msgId in this case..

public static string UrlEncode(this string text) => Uri.EscapeDataString(text);

@andrueastman
Copy link
Member

Any chance you are able to share the contents of the response if you try this out to confirm if the response is indeed valid json?

            var requestInformation = graphClient.Me.Messages[msgId].ToGetRequestInformation();
            var responseStream = await graphClient.RequestAdapter.SendPrimitiveAsync<Stream>(requestInformation);
            using var streamReader = new StreamReader(responseStream);
            var response = await streamReader.ReadToEndAsync();
            Console.Write(response);

@bagdxk
Copy link
Author

bagdxk commented Jul 6, 2023

Tested, the responsestream is null, in the code above.

And try below code, the body is empty string. And confirmed the statuscode is 200.

            var request = await _client.RequestAdapter.ConvertToNativeRequestAsync<HttpRequestMessage>(_client.Me.Messages[msgId.UrlEncode()].ToGetRequestInformation());
            HttpClient httpClient = new HttpClient();
            var response = httpClient.Send(request);
            var body = await response.Content.ReadAsStringAsync();

@andrueastman
Copy link
Member

Thanks for the getting back @bagdxk

With the body is empty, any chance you can also confirm whether there is a value set for the content header? Ideally the serializer should be invoked if there is non-null content (which means there should also be no content type).

response.Content.Headers.ContentType

@bagdxk
Copy link
Author

bagdxk commented Jul 6, 2023

The contenttype is

{application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8}
CharSet [string]:
"utf-8"
MediaType [string]:
"application/json"
Parameters [ICollection]:
Count = 4
[0] [NameValueHeaderValue]:
{odata.metadata=minimal}
[1] [NameValueHeaderValue]:
{odata.streaming=true}
[2] [NameValueHeaderValue]:
{IEEE754Compatible=false}
[3] [NameValueHeaderValue]:
{charset=utf-8}
Raw View
Non-Public members

@bagdxk
Copy link
Author

bagdxk commented Jul 6, 2023

Thanks @andrueastman the quick fix from client sdk side.
BTW is this a graph api server side issue too? May I know where I can report the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants