How to fixTypeLoadException: Could not load type 'Microsoft.Graph.IAuthenticationProviderOption' from assembly 'Microsoft.Graph.Core, Version=3.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Eric Lauwers 0 Reputation points
2025-02-18T06:59:59.4866667+00:00

I am using Microsoft Graph 5.69 <PackageReference Include="Microsoft.Graph" Version="5.69.0" />

Each time, I register the Microsoft Graph service in program.cs

builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)

 .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));

builder.Services.AddMicrosoftGraph(options =>

{

 options.BaseUrl = "https://graph.microsoft.com/v1.0/";

 options.Scopes = "User.Read";

});

// Add authorization

builder.Services.AddAuthorization();

and run the app, I get the following error

An unhandled exception occurred while processing the request.

TypeLoadException: Could not load type 'Microsoft.Graph.IAuthenticationProviderOption' from assembly 'Microsoft.Graph.Core, Version=3.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Microsoft.Identity.Web.GraphServiceCollectionExtensions+<>c.<AddMicrosoftGraph>b__1_0(IServiceProvider serviceProvider)

How can I fix this?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,113 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,665 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.