'Application crash while requesting the events from Microsoft outlook
Description
We have created an application to access the outlook event and show it on list view. We are authenticating the account by using the client id and we faced the System.TypeLoadException but it is working fine in windows.
We configure the sample by the steps below:
- Register the new project on https://portal.azure.com/
- Enable calendar read write permission for the project
- Create the IPublicClientApplication on App.cs by client id.
- Configure the Android project and authenticate the user by AcquireTokenInteractive and GraphServiceClient
The exception was raised while get events after the authentication.
Client.Me.Events.Request().GetAsync();
Note: The issue did not raised on Windows
Snippets:
In App.cs
public static IPublicClientApplication IdentityClientApp;
//You need to replace your Application ID
public static string ClientID = "ClientID";
public static string[] Scopes = { "User.Read", "Calendars.Read", "Calendars.ReadWrite" };
public static object ParentWindow { get; set; }
public App()
{
InitializeComponent();
IdentityClientApp = PublicClientApplicationBuilder.Create(ClientID)
.WithRedirectUri($"msal{ClientID}://auth")
.Build();
MainPage = new MainPage();
}
In MainActivity
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
App.ParentWindow = this;
}
In MainPage,
private Microsoft.Graph.GraphServiceClient Client = null;
private AuthenticationResult tokenRequest;
public MainPage()
{
InitializeComponent();
}
private void Authenticate()
{
Client = new Microsoft.Graph.GraphServiceClient("https://graph.microsoft.com/v1.0",
new Microsoft.Graph.DelegateAuthenticationProvider(async (requestMessage) =>
{
List<IAccount> users = (List<IAccount>)await App.IdentityClientApp.GetAccountsAsync();
if (users == null || users.Count == 0)
tokenRequest = await App.IdentityClientApp.AcquireTokenInteractive(App.Scopes)
.WithParentActivityOrWindow(App.ParentWindow)
.WithUseEmbeddedWebView(true).ExecuteAsync();
else
tokenRequest = await App.IdentityClientApp.AcquireTokenSilent(App.Scopes, users.FirstOrDefault()).ExecuteAsync();
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", tokenRequest.AccessToken);
}));
}
private async void OnClicked(object sender, EventArgs e)
{
this.Authenticate();
var events = Client.Me.Events.Request().GetAsync();
var list = events.ToList();
}
Crash:
System.TypeLoadException Message=Could not resolve type with token 01000023 from typeref (expected class 'System.Threading.Tasks.ValueTask`1' in assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
