title: Can't call microsoft graph api from sharepoint
body: <p>I create a sharepoint webpart 2019, and want to connect to Microsoft Graph api. However when calling the api i get the following error:</p>
  <pre><code>&quot;Could not load file or assembly 'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.&quot;
  </code></pre>
  <p>This is my code:</p>
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
       connectGraph().GetAwaiter().GetResult();
  }
  
  private async Task&lt;GraphServiceClient&gt; connectGraph()
  {
      try
      {
           string Tenant = &quot;*************************************&quot;;
           string ClientId = &quot;*************************************&quot;;
           string ClientSecret = &quot;*************************************&quot;;
           GraphServiceClient Client;
           PublicClientApplicationBuilder clientApp = PublicClientApplicationBuilder.Create(ClientId);
           IAuthenticationProvider authenticationProvider = new DelegateAuthenticationProvider(async (requestMessage) =&gt;
           {
                if (BearerToken == null || BearerToken.IsExpired())
                {
                     string accessToken = GetUserAccessTokenAsync(clientApp.Build());
                }
                // Append the access token to the request.
                requestMessage.Headers.Authorization = new AuthenticationHeaderValue(&quot;bearer&quot;, BearerToken.access_token);});
                Client = new GraphServiceClient(authenticationProvider);
                var user = await Client.Users[&quot;user@example.com&quot;].Request().GetAsync();
                test.Text = user.DisplayName;
           }
      }
  }
  
  private string GetUserAccessTokenAsync(IPublicClientApplication clientApp)
  {
      string[] Scopes = { &quot;Directory.AccessAsUser.All&quot; };
      string token = null;
      AuthenticationResult authResult = clientApp.AcquireTokenInteractive(Scopes).ExecuteAsync().Result;
      token = authResult.AccessToken;
      BearerToken = new Token();
      BearerToken.access_token = token;
      return token;
  }
  
  public class Token
  {
      public string access_token;
      public int expires_in;
      public int expires_on;
      public int not_before;
      public string token_type;
  }
  
  </code></pre>
  <p>The user interface is simple</p>
  <pre><code>&lt;asp:TextBox ID=&quot;test&quot; runat=&quot;server&quot;&gt;&lt;/asp:TextBox&gt;
  </code></pre>
  <p>I notice my nuget package are blue. Not sure if this is the cause of why I get the error</p>
  <p><a href="https://i.stack.imgur.com/GizvK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GizvK.png" alt="enter image description here" /></a></p>
  <p>The errors occurs when i run the</p>
  <pre><code>var user = await Client.Users[&quot;user@example.com&quot;].Request().GetAsync();
  </code></pre>