microsoftgraph / msgraph-sdk-dotnet

Microsoft Graph Client Library for .NET!
https://graph.microsoft.com
Other
703 stars 249 forks source link

Race condition when creating a OneNote page and retrieving its preview inmediately afterwards #386

Closed arcadiogarcia closed 3 years ago

arcadiogarcia commented 5 years ago

Please provide the following (and please check them off the list with [x]) before submitting this issue:

Expected behavior

I'm using this code to create a OneNote page and get its preview afterwards:

string htmlBody = $"< !DOCTYPE html >< html >  < head >< title > </ title ></head>  <body></body></html> ";
 byte[] byteArray = Encoding.ASCII.GetBytes(htmlBody);
using (MemoryStream stream = new MemoryStream(byteArray))
            {
                // Create a OneNote page.
                var emptyPage = new OnenotePage() { Title = "New page", Content = stream };
                page = await client.Me.Onenote.Sections[sectionId].Pages.Request().AddAsync(stream, "text/html");
            }
// await Task.Delay(1000);
var preview = await client.Me.Onenote.Pages[x.Id].Preview().Request().GetAsync();

Which should work as expected.

Actual behavior

When running the code I get the following exception:

Microsoft.Graph.ServiceException: 'Code: 20102
Message: The specified resource ID does not exist.

After playing with it I found that if I add the commented Task.Delay the exception doesn't happen anymore, so my guess is that the second request is happening before the notebook is actually created, and by introducing the delay I'm avoiding the race condition. Since I'm already awaiting the AddAsync method, I would expect the page to be created before the second request happens.

Steps to reproduce the behavior

I'm using version 1.12.0 of the sdk

AB#7316

MIchaelMainer commented 3 years ago

Please reopen this issue if this bug still exists.