Could not resolve type with token 01000021 from typeref

Dmitriy Reznik 236 Reputation points
2023-01-19T17:52:56.6433333+00:00

I am trying to create virtual appointments based on this documentation:
https://learn.microsoft.com/en-us/graph/api/application-post-onlinemeetings?view=graph-rest-1.0&tabs=csharp

Here is my code:

            InteractiveBrowserCredentialOptions options = new()
            {
                TenantId = B2CConstants.TenantId,
                ClientId = B2CConstants.ClientId,
                AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
                // MUST be http://localhost or http://localhost:PORT
                // See https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/System-Browser-on-.Net-Core
                RedirectUri = new Uri("http://localhost"),
            };
            // https://learn.microsoft.com/dotnet/api/azure.identity.interactivebrowsercredential
            var interactiveCredential = new InteractiveBrowserCredential(options);
            GraphServiceClient graphClient = new(interactiveCredential, B2CConstants.Scopes);
            var onlineMeeting = new OnlineMeeting
            {
                StartDateTime = DateTimeOffset.Parse("2023-02-17T18:00:34.2444915+00:00"),
                EndDateTime = DateTimeOffset.Parse("2023-02-17T18:30:34.2464912+00:00"),
                ExternalId = Guid.NewGuid().ToString(),
                Subject = "User Token Meeting"
            };
            try
            {
                await graphClient.Me.OnlineMeetings
                    .Request()
                    .AddAsync(onlineMeeting);
            }
            catch (Exception ex)
            {
            }

AddAsync() throws an exception:

{Status Code: 0
Microsoft.Graph.ServiceException: Code: generalException
Message: An error occurred sending the request.

 ---> System.TypeLoadException: Could not load type of field 'Microsoft.Graph.TokenCredentialAuthProvider+<AuthenticateRequestAsync>d__3:<>u__1' (4) due to: Could not resolve type with token 01000021 from typeref (expected class 'System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1' in assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e') assembly:mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e type:System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1 member:(null)
   at Microsoft.Graph.AuthenticationHandler.SendAsync(HttpRequestMessage httpRequestMessage, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Microsoft.Graph.BaseRequest.<SendAsync>d__34`1[[Microsoft.Graph.OnlineMeeting, Microsoft.Graph, Version=4.49.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].MoveNext()
   at LATICRETE_MobileApp.Features.VideoChat.VideoChatPageModel.CreateMeetingAsync() in C:\Git Repos\LATICRETE Mobile App\LATICRETE_MobileApp\Features\VideoChat\VideoChatPageModel.cs:line 139}

Could you please explain what I am missing?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,521 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,204 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 47,716 Reputation points
    2023-01-19T18:34:38.9333333+00:00

    The error message indicates mscorlib v2. That would be the pre-CLR v4 runtime. You cannot use async with a CLR version that old. What version of the framework is your code compiling against? It needs to be at least .NET Framework 4.6.2.

    If the code runs fine locally but fails when you run it on IIS then ensure you have configured the app pool to be using the CLR v4 version.