c# Graph Api > 5..0.15 Content.GetAsync() not working any more

Uwe Schöneis 10 Reputation points
2023-08-11T09:45:01.1066667+00:00
// https://learn.microsoft.com/en-us/answers/questions/1025116/how-to-download-a-mail-graph-api-c?orderby=oldest
Stream mimeContentStream = await _graphClient.Users[{someUseriD}].Messages[{aMessageId}].Content.GetAsync();
string mailFile = "anyFileName.eml";
using (var fileStream = System.IO.File.Create(mailFile))               
{
	mimeContentStream.Seek(0, SeekOrigin.Begin);
	mimeContentStream.CopyTo(fileStream);
};

On updating the graph API from 5.0.15 to any higher version mimeContentStream is invalid.
Is this by design? If the request is no longer supported there should be at least an error, exception, or whatever.
Returning an invalid stream is NOT an option as it breaks the compatibility whith the existing code, based on Graph API 5.0.x.
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,323 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,449 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,164 questions
{count} vote

2 answers

Sort by: Most helpful
  1. jcq 6 Reputation points
    2023-09-26T15:20:09.11+00:00

    Here i have solution with 5.28:

    https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2144

    And this worked for me, my problem was with reading the stream (old method doesn't work anymore).

    var res = await graphServiceClient.Me.Messages["{message-id}"].Content.GetAsync();
    var data = new StreamReader(res).ReadToEnd();
    
    1 person found this answer helpful.
    0 comments No comments

  2. Uwe Schöneis 0 Reputation points
    2023-09-27T05:11:24.74+00:00

    Thanks jcq for digging into it! It works including V5.0.15. Hopefully MS will provide working sample code as they change the graph version ....

    0 comments No comments