Could not resolve type with token 01000021 from typeref

Dmitriy Reznik 236 Reputation points
2023-01-19T17:49:10.1166667+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+
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,683 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,879 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 37,216 Reputation points
    2023-01-20T08:35:38.0333333+00:00

    Hi @Dmitriy Reznik

    I tried creating an online meeting using the graph C# SDK and it worked fine. Refer to the sample code:

    using Azure.Identity; 
    using Microsoft.Graph;
    
    
    var scopes = new[] { "OnlineMeetings.ReadWrite" };
    
    var tenantId = "{tenant id of the azure ad}";
    
    // Value from app registration
    var clientId = "{client id}";
    
    // using Azure.Identity;
    var options = new TokenCredentialOptions
    {
        AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
    };
    
    var userName = "{user name}";
    var password = "{password}";
    
    // https://learn.microsoft.com/dotnet/api/azure.identity.usernamepasswordcredential
    var userNamePasswordCredential = new UsernamePasswordCredential(
        userName, password, tenantId, clientId, options);
    
    var graphClient = new GraphServiceClient(userNamePasswordCredential, scopes);
    
    var onlineMeeting = new OnlineMeeting
    {
          StartDateTime = DateTimeOffset.Parse("2023-07-12T21:30:34.2444915+00:00"),
          EndDateTime = DateTimeOffset.Parse("2023-07-12T22:00:34.2464912+00:00"),
          Subject = "Test Meeting"
    };
    
    try
    {
       await graphClient.Me.OnlineMeetings
       .Request()
       .AddAsync(onlineMeeting);
    }
    catch (Exception ex) { 
    
          Console.WriteLine(ex);
    }
    
    

    By the way, based on my tests, creating an online meeting in an Azure B2C tenant is not currently supported.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".