Received an invalid status line: '0'

Vitalie-Alexandru Duca 25 Reputation points
2023-03-06T15:09:52.43+00:00

Greetings,

I am using the Graph API via the Microsoft.Graph SDK in a .NET 5 console application to update some messages. Since the middle of February, I've been noticing failing requests that happen sometimes (but quite often).

This is the exception I've been seeing:

Code: generalException
Message: An error occurred sending the request

This is the inner exception:

System.Net.Http.HttpRequestException: Received an invalid status line: '0'.
   at Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Microsoft.Graph.BaseRequest.SendAsync[T](Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Microsoft.Graph.MessageRequest.UpdateAsync(Message messageToUpdate, CancellationToken cancellationToken)

I haven't updated the SDK to the latest version since there are a lot of breaking changes and it is difficult to deploy a new version of my application. I have also tried to perform the same operations via the Graph Explorer, but haven't been able to reproduce it there.

Any help is much appreciated. Thank you in advance.

P.S. This question is a duplicate. My previous question was taken down for no reason and made available again.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,447 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Md Asif Muztaba 320 Reputation points Microsoft Vendor
    2023-11-30T03:21:35.3666667+00:00

    The error you’re encountering, “Received an invalid status line: ‘0’”, is a known issue that some developers have reported when using the Microsoft.Graph SDK in .NET applications. This error typically occurs when the SDK encounters an unexpected response from the server.

    Here are a few suggestions that might help you troubleshoot this issue:

    Update the SDK: Although you mentioned that updating the SDK could introduce breaking changes, it’s possible that this issue has been addressed in a newer version of the SDK. It might be worth considering this option if other solutions don’t work.

    1. Check the Access Token: Ensure that your application is presenting a valid access token to Microsoft Graph as part of the request. This error often means that the access token may be missing in the HTTP authenticate request header or that the token is invalid or has expired.
    2. Set the “Accept” Header: Try setting the “Accept” header explicitly in your request. Some developers have found that this can help avoid issues with unexpected server responses.

    Reproduce the Issue Outside the SDK: You mentioned that you couldn’t reproduce the issue using the Graph Explorer. If possible, try to reproduce the issue using a different method (like a simple HTTP client) to see if the issue is specific to the SDK or if it’s a more general issue with the Graph API.

    Remember, these are just suggestions and might solve your specific issue. Good luck! 😊

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments