-
Notifications
You must be signed in to change notification settings - Fork 260
Description
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.
- 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.
- 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": "myaddress@mycompany.com",
"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": "myaddress@mycompany.com",
"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": "hisaddress@mycompany.com",
"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": "321DC8B86A0C41498D776B1374091089@eurprd07.prod.outlook.com"
}
],
"sender": {
"emailAddress": {
"address": "myaddress@mycompany.com",
"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": "myaddress@mycompany.com",
"name": "My Name"
}
},
"hasAttachments": true,
"receivedDateTime": "2024-08-22T09:35:01+00:00",
"replyTo": [],
"sender": {
"emailAddress": {
"address": "myaddress@mycompany.com",
"name": "My Name"
}
},
"sentDateTime": "2024-08-22T09:34:47+00:00",
"subject": "Small attachment",
"toRecipients": [
{
"emailAddress": {
"address": "hisaddress@mycompany.com",
"name": "His Name"
}
}
],
"attachments": [
{
"contentBytes": "U21hbGwgYXR0YWNobWVudA==",
"contentId": "321DC8B86A0C41498D776B1374091089@eurprd07.prod.outlook.com",
"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_