Для решения этой проблемы я тестирую его на своей стороне с той же версией Microsoft.Graph
(Microsoft.Graph.Beta -Version 0.19.0-preview) с вами. Но он отлично работает на моей стороне, поэтому я предоставляю свой код ниже для вашей справки.
using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;
using System;
using System.Security;
using System.Threading.Tasks;
namespace ConsoleApp22
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
var clientId = "xxx";
var tenantID = "xxx";
string[] scopes = new string[] { "User.Read" };
var email = "xxx";
var str = "xxx";
var password = new SecureString();
foreach (char c in str) password.AppendChar(c);
IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.Build();
UsernamePasswordProvider authProvider = new UsernamePasswordProvider(publicClientApplication, scopes);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
User me = await graphClient.Me.Request()
.WithUsernamePassword(email, password)
.GetAsync();
Console.WriteLine(me.Id + "===" + me.DisplayName);
}
}
}
![enter image description here](https://i.stack.imgur.com/3TMlr.png)
For your issue, could you please create a new project and install the same packages with me in the screenshot above, and then try it again.
By the way, I ran the code with .net core 3.1
=======================Update======================
If you can't make your main
method async, you can write the code as below:
![enter image description here](https://i.stack.imgur.com/eMObS.png)
Or if your execution code is in another class, you can write the code as:
введите описание изображения здесь