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

Serializing an email message with file attachments does not serialize everything #2638

Closed
RogerTimmerman opened this issue Aug 26, 2024 · 3 comments
Labels

Comments

@RogerTimmerman
Copy link

Describe the bug

Hi,
We recently upgraded our application from Microsoft Graph SDK v4 to v5 and found an annoying issue in v5 in serialization of email messages with file-attachments to Json string format after receipt of an email via the Graph API's.
The serialization is performed and stored and later deserialize the Json to a email message again and e.g. forward that email including extra information.

  1. Using JsonSerializer at least the contentbytes (the most important part) of the file is missing from the attachments property in the Json output string. Note that serializing in SDK v4, did deliver the complete email content.
  2. Using KiotaJsonSerializer all email properties are missing in Json output string except the attachments property (however does contain the contentbytes)

The actual questions are:

  • Can somebody provide me a (small) C# (within .Net framework 4.8) code example how to tackle this issue as the Microsoft documentation (about untyped nodes etc.) does not help me that much.
  • Or is this an actual serialization issue that needs repair
  • Also I wonder whether a Json file serialized within SDK 4 can be deserialized directly within SDK 5 (concerning the breaking changes made0.

Replies are appreciated,
With regards
Roger Timmerman

We are using Microsoft graph SDK 5.56.0 (Microsoft.Graph.Core 3.1.15) and related dependencies.

Read email message code part:
string[] properties = new string[] { "BccRecipients","Body", "CcRecipients", "CreatedDateTime", "From", "HasAttachments", "Id", "LastModifiedDateTime",
"ReceivedDateTime", "ReplyTo", "Sender", "SentDateTime", "Subject", "ToRecipients" };
Task.Run(async () =>
{
retrievedMessage = await _graphClient.Users[accountName]
.Messages[msGraphMessageId]
.GetAsync(requestConfiguration => requestConfiguration
.QueryParameters.Select = properties);
}).Wait(RequestTimeoutMs);

Inspecting the retrievedMessage object reveals all properties (including file content) are there.

Expected behavior

The expected behavior is that alike SDK v4, Json output contains all relevant properties

How to reproduce

        string[] properties = new string[] { "BccRecipients","Body", "CcRecipients", "CreatedDateTime", "From", "HasAttachments", "Id", "LastModifiedDateTime", 
            "ReceivedDateTime", "ReplyTo", "Sender", "SentDateTime", "Subject", "ToRecipients" };
        Task.Run(async () =>
        {
            retrievedMessage = await _graphClient.Users[accountName]
            .Messages[msGraphMessageId]
            .GetAsync(requestConfiguration => requestConfiguration
                      .QueryParameters.Select = properties);
        }).Wait(RequestTimeoutMs);

        string json;
        json = JsonSerializer.Serialize(retrievedMessage);

// or:
json = KiotaJsonSerializer.SerializeAsStringAsync<Microsoft.Graph.Models.Message>(retrievedMessage).Result;

SDK Version

SDK 5.56.0 (Microsoft.Graph.Core 3.1.15)

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```

Examples of serialization (v5 using JsonSerializer, v5 KiotaJsonSerializer, v4 using JsonSerializer):

  • Serialization in SDK 5 using JsonSerializer (file content is missing)
    {
    "Attachments": [
    {
    "ContentType": "text/plain",
    "IsInline": false,
    "LastModifiedDateTime": "2024-08-22T09:35:01+00:00",
    "Name": "small-attachment.txt",
    "Size": 340,
    "AdditionalData": {
    "@odata.mediaContentType": "text/plain"
    },
    "BackingStore": {
    "InitializationCompleted": false,
    "ReturnOnlyChangedValues": false
    },
    "Id": "AQMkAGMzNjQ3OWJlLWRjNWItNDA2Yy04YjgxLWFiZWJmYmFiMmQ4NQBGAAADAXcZWMvdbEaSDZn7g6eWdAcAyJ0XzcbX2UiDcSve6RCRbQAAAgEMAAAAyJ0XzcbX2UiDcSve6RCRbQADejg3jAAAAAESABAA5Ba9GDKzzEiqXUYQ4M_hGA==",
    "OdataType": "#microsoft.graph.fileAttachment"
    }
    ],
    "BccRecipients": [],
    "Body": {
    "AdditionalData": {},
    "BackingStore": {
    "InitializationCompleted": true,
    "ReturnOnlyChangedValues": false
    },
    "Content": "\r\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="Generator" content="Microsoft Word 15 (filtered medium)"><style>\r\n\r\n</style><body lang="EN-US" link="#467886" vlink="#96607D" style="word-wrap:break-word"><div class="WordSection1"><p class="MsoNormal"><span lang="EN-GB">Test with Small attachment

    ",
    "ContentType": 1,
    "OdataType": null
    },
    "BodyPreview": null,
    "CcRecipients": [],
    "ConversationId": null,
    "ConversationIndex": null,
    "Extensions": null,
    "Flag": null,
    "From": {
    "AdditionalData": {},
    "BackingStore": {
    "InitializationCompleted": true,
    "ReturnOnlyChangedValues": false
    },
    "EmailAddress": {
    "AdditionalData": {},
    "Address": "[email protected]",
    "BackingStore": {
    "InitializationCompleted": true,
    "ReturnOnlyChangedValues": false
    },
    "Name": "My Name",
    "OdataType": null
    },
    "OdataType": null
    },
    "HasAttachments": true,
    "Importance": null,
    "InferenceClassification": null,
    "InternetMessageHeaders": null,
    "InternetMessageId": null,
    "IsDeliveryReceiptRequested": null,
    "IsDraft": null,
    "IsRead": null,
    "IsReadReceiptRequested": null,
    "MultiValueExtendedProperties": null,
    "ParentFolderId": null,
    "ReceivedDateTime": "2024-08-22T09:35:01+00:00",
    "ReplyTo": [],
    "Sender": {
    "AdditionalData": {},
    "BackingStore": {
    "InitializationCompleted": true,
    "ReturnOnlyChangedValues": false
    },
    "EmailAddress": {
    "AdditionalData": {},
    "Address": "[email protected]",
    "BackingStore": {
    "InitializationCompleted": true,
    "ReturnOnlyChangedValues": false
    },
    "Name": "My Name",
    "OdataType": null
    },
    "OdataType": null
    },
    "SentDateTime": "2024-08-22T09:34:47+00:00",
    "SingleValueExtendedProperties": null,
    "Subject": "Small attachment",
    "ToRecipients": [
    {
    "AdditionalData": {},
    "BackingStore": {
    "InitializationCompleted": false,
    "ReturnOnlyChangedValues": false
    },
    "EmailAddress": {
    "AdditionalData": {},
    "Address": "[email protected]",
    "BackingStore": {
    "InitializationCompleted": false,
    "ReturnOnlyChangedValues": false
    },
    "Name": "His Name",
    "OdataType": null
    },
    "OdataType": null
    }
    ],
    "UniqueBody": null,
    "WebLink": null,
    "Categories": null,
    "ChangeKey": null,
    "CreatedDateTime": "2024-08-22T09:35:01+00:00",
    "LastModifiedDateTime": "2024-08-22T09:35:17+00:00",
    "AdditionalData": {
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('hisaddress%40mycompany.com')/messages(bccRecipients,body,ccRecipients,createdDateTime,from,hasAttachments,id,lastModifiedDateTime,receivedDateTime,replyTo,sender,sentDateTime,subject,toRecipients)/$entity",
    "@odata.etag": "W/"CQAAABYAAADInRfNxtfZSINxK97pEJFtAAN54mtE""
    },
    "BackingStore": {
    "InitializationCompleted": true,
    "ReturnOnlyChangedValues": false
    },
    "Id": "AQMkAGMzNjQ3OWJlLWRjNWItNDA2Yy04YjgxLWFiZWJmYmFiMmQ4NQBGAAADAXcZWMvdbEaSDZn7g6eWdAcAyJ0XzcbX2UiDcSve6RCRbQAAAgEMAAAAyJ0XzcbX2UiDcSve6RCRbQADejg3jAAAAA==",
    "OdataType": "#microsoft.graph.message"
    }

  • Serialization in SDK 5 using KiotaJsonSerializer (most properties are missing)
    {
    "attachments": [
    {
    "id": "AQMkAGMzNjQ3OWJlLWRjNWItNDA2Yy04YjgxLWFiZWJmYmFiMmQ4NQBGAAADAXcZWMvdbEaSDZn7g6eWdAcAyJ0XzcbX2UiDcSve6RCRbQAAAgEMAAAAyJ0XzcbX2UiDcSve6RCRbQADejg3jAAAAAESABAA5Ba9GDKzzEiqXUYQ4M_hGA==",
    "@odata.type": "#microsoft.graph.fileAttachment",
    "@odata.mediaContentType": "text/plain",
    "contentType": "text/plain",
    "isInline": false,
    "lastModifiedDateTime": "2024-08-22T09:35:01+00:00",
    "name": "small-attachment.txt",
    "size": 340,
    "contentBytes": "U21hbGwgYXR0YWNobWVudA==",
    "contentId": "[email protected]"
    }
    ],
    "sender": {
    "emailAddress": {
    "address": "[email protected]",
    "name": "My Name"
    }
    }
    }

  • Serialization in SDK 4 using JsonSerializer (everything is present)
    {
    "bccRecipients": [],
    "body": {
    "content": "\r\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="Generator" content="Microsoft Word 15 (filtered medium)"><style>\r\n\r\n</style><body lang="EN-US" link="#467886" vlink="#96607D" style="word-wrap:break-word"><div class="WordSection1"><p class="MsoNormal"><span lang="EN-GB">Test with Small attachment

    ",
    "contentType": "Html"
    },
    "ccRecipients": [],
    "from": {
    "emailAddress": {
    "address": "[email protected]",
    "name": "My Name"
    }
    },
    "hasAttachments": true,
    "receivedDateTime": "2024-08-22T09:35:01+00:00",
    "replyTo": [],
    "sender": {
    "emailAddress": {
    "address": "[email protected]",
    "name": "My Name"
    }
    },
    "sentDateTime": "2024-08-22T09:34:47+00:00",
    "subject": "Small attachment",
    "toRecipients": [
    {
    "emailAddress": {
    "address": "[email protected]",
    "name": "His Name"
    }
    }
    ],
    "attachments": [
    {
    "contentBytes": "U21hbGwgYXR0YWNobWVudA==",
    "contentId": "[email protected]",
    "contentType": "text/plain",
    "isInline": false,
    "lastModifiedDateTime": "2024-08-22T09:35:01+00:00",
    "name": "small-attachment.txt",
    "size": 340,
    "id": "AQMkAGMzNjQ3OWJlLWRjNWItNDA2Yy04YjgxLWFiZWJmYmFiMmQ4NQBGAAADAXcZWMvdbEaSDZn7g6eWdAcAyJ0XzcbX2UiDcSve6RCRbQAAAgEMAAAAyJ0XzcbX2UiDcSve6RCRbQADejg3jAAAAAESABAA5Ba9GDKzzEiqXUYQ4M_hGA==",
    "@odata.type": "#microsoft.graph.fileAttachment",
    "@odata.mediaContentType": "text/plain"
    }
    ],
    "createdDateTime": "2024-08-22T09:35:01+00:00",
    "lastModifiedDateTime": "2024-08-22T09:35:17+00:00",
    "id": "AQMkAGMzNjQ3OWJlLWRjNWItNDA2Yy04YjgxLWFiZWJmYmFiMmQ4NQBGAAADAXcZWMvdbEaSDZn7g6eWdAcAyJ0XzcbX2UiDcSve6RCRbQAAAgEMAAAAyJ0XzcbX2UiDcSve6RCRbQADejg3jAAAAA==",
    "@odata.type": "microsoft.graph.message",
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('hisaddress%40mycompany.com')/messages(bccRecipients,body,ccRecipients,createdDateTime,from,hasAttachments,id,lastModifiedDateTime,receivedDateTime,replyTo,sender,sentDateTime,subject,toRecipients)/$entity",
    "@odata.etag": "W/"CQAAABYAAADInRfNxtfZSINxK97pEJFtAAN54mtE""
    }

</details>


### Configuration

OS: Windows server 2019 64 bits

### Other information

_No response_
@RogerTimmerman RogerTimmerman added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Aug 26, 2024
@andrueastman
Copy link
Member

Thanks for raising this @RogerTimmerman

This is related to the issue at microsoft/kiota-dotnet#310 and resolved with microsoft/kiota-dotnet#311

Any chance you can confirm that the code below works if you include the latest version of https://www.nuget.org/packages/Microsoft.Kiota.Abstractions/ (This will be included automatically in the next SDK version) the following works out for you?

var jsonString = await KiotaSerializer.SerializeAsStringAsync("application/json", result, false);

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Aug 27, 2024
@RogerTimmerman
Copy link
Author

Hi @andrueastman
Thanks for the response,
I will check as soon as possible.
Roger

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Aug 27, 2024
@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Aug 27, 2024
@RogerTimmerman
Copy link
Author

@andrueastman
Hi Andrew,

I now use a newer Microsoft.Kiota.Abstractions (>= 1.12.0) assembly and it works,
Emails are serialized and deserialized properly, with and without attachments.

Thanks for the guidance
With regards
Roger Timmerman

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@andrueastman @RogerTimmerman and others