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?

Developer technologies | .NET | Blazor
Microsoft Security | Microsoft Graph

Your answer

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