diff --git a/MicrosoftGraphAspNetCoreConnectSample/Helpers/GraphService.cs b/MicrosoftGraphAspNetCoreConnectSample/Helpers/GraphService.cs index 8f6a0a3..a103e84 100644 --- a/MicrosoftGraphAspNetCoreConnectSample/Helpers/GraphService.cs +++ b/MicrosoftGraphAspNetCoreConnectSample/Helpers/GraphService.cs @@ -194,18 +194,21 @@ public static async Task SendEmail(GraphServiceClient graphClient, IHostingEnvir // Load user's profile picture. var pictureStream = await GetMyPictureStream(graphClient, httpContext); - // Copy stream to MemoryStream object so that it can be converted to byte array. - var pictureMemoryStream = new MemoryStream(); - await pictureStream.CopyToAsync(pictureMemoryStream); - - // Convert stream to byte array and add as attachment. - attachments.Add(new FileAttachment + if (pictureStream != null) { - ODataType = "#microsoft.graph.fileAttachment", - ContentBytes = pictureMemoryStream.ToArray(), - ContentType = "image/png", - Name = "me.png" - }); + // Copy stream to MemoryStream object so that it can be converted to byte array. + var pictureMemoryStream = new MemoryStream(); + await pictureStream.CopyToAsync(pictureMemoryStream); + + // Convert stream to byte array and add as attachment. + attachments.Add(new FileAttachment + { + ODataType = "#microsoft.graph.fileAttachment", + ContentBytes = pictureMemoryStream.ToArray(), + ContentType = "image/png", + Name = "me.png" + }); + } } catch (Exception e) {