Skip to content
This repository was archived by the owner on Apr 12, 2023. It is now read-only.

Commit 8870a81

Browse files
authored
Merge pull request #53 from juanpescador/fix-uncaught-exception-send-email
Fix uncaught exception when sending email
2 parents 03267f8 + e4078a7 commit 8870a81

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

MicrosoftGraphAspNetCoreConnectSample/Helpers/GraphService.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,21 @@ public static async Task SendEmail(GraphServiceClient graphClient, IHostingEnvir
194194
// Load user's profile picture.
195195
var pictureStream = await GetMyPictureStream(graphClient, httpContext);
196196

197-
// Copy stream to MemoryStream object so that it can be converted to byte array.
198-
var pictureMemoryStream = new MemoryStream();
199-
await pictureStream.CopyToAsync(pictureMemoryStream);
200-
201-
// Convert stream to byte array and add as attachment.
202-
attachments.Add(new FileAttachment
197+
if (pictureStream != null)
203198
{
204-
ODataType = "#microsoft.graph.fileAttachment",
205-
ContentBytes = pictureMemoryStream.ToArray(),
206-
ContentType = "image/png",
207-
Name = "me.png"
208-
});
199+
// Copy stream to MemoryStream object so that it can be converted to byte array.
200+
var pictureMemoryStream = new MemoryStream();
201+
await pictureStream.CopyToAsync(pictureMemoryStream);
202+
203+
// Convert stream to byte array and add as attachment.
204+
attachments.Add(new FileAttachment
205+
{
206+
ODataType = "#microsoft.graph.fileAttachment",
207+
ContentBytes = pictureMemoryStream.ToArray(),
208+
ContentType = "image/png",
209+
Name = "me.png"
210+
});
211+
}
209212
}
210213
catch (Exception e)
211214
{

0 commit comments

Comments
 (0)