Could not load file or assembly ‘Microsoft.IdentityModel.Abstractions, Version=6.35.0.0. Nuget version mismatch Microsoft.IdentityModel.Abstractions

Subhasis Ghosh 0 Reputation points
2024-12-20T16:00:23.2666667+00:00

I am developing a C# dll based on .NET framework 4.8.2 which will use Microsoft Graph API to send email through outlook.

For this I have added the latest Nuget packages for “Microsoft.Graph” v5.67.0 and "Microsoft.Identity.Client" v4.66.2 . This is my csproj -

<ItemGroup>

<PackageReference Include="Microsoft.Graph">

<Version>5.67.0</Version>

</PackageReference>

<PackageReference Include="Microsoft.Identity.Client">

<Version>4.66.2</Version>

</PackageReference>

<PackageReference Include="Microsoft.Windows.Compatibility">

<Version>9.0.0</Version>

</PackageReference>

<PackageReference Include="Newtonsoft.Json">

<Version>13.0.1</Version>

</PackageReference>

<PackageReference Include="Std.UriTemplate" Version="2.0.1.0" />

<PackageReference Include="Microsoft.CSharp">

<Version>4.7.0</Version>

</PackageReference>

</ItemGroup>

The build is successfull but I am getting this runtime error -

System.IO.FileLoadException: Could not load file or assembly ‘Microsoft.IdentityModel.Abstractions, Version=6.35.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

File name: ‘Microsoft.IdentityModel.Abstractions, Version=6.35.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’

Now, “Microsoft.Graph” v5.67.0 is dependent upon latest 'Microsoft.IdentityModel.Abstractions, Version=8.2.0.0 but I am not able to figure out which module is dependent upon 6.35.0.0.

Upon further looking, it is found out that, in obj/project.asset.json file there is a mismatch between 'Microsoft.IdentityModel components. “Microsoft.Graph.Core/3.2.1” is referring to “Microsoft.IdentityModel.Validators”: “8.2.0” but "Microsoft.Identity.Client/4.66.2"is referring to old 6.35.0 version.

Here is the obj/project.asset.json file -

"Microsoft.Graph/5.67.0": {

"type": "package",

"dependencies": {

"Microsoft.Graph.Core": "3.2.1"

},

"Microsoft.Graph.Core/3.2.1": {

"type": "package",

"dependencies": {

"Microsoft.IdentityModel.Protocols.OpenIdConnect": "8.2.0",

"Microsoft.IdentityModel.Validators": "8.2.0",

"Microsoft.Kiota.Abstractions": "1.15.2",

"Microsoft.Kiota.Authentication.Azure": "1.15.2",

"Microsoft.Kiota.Http.HttpClientLibrary": "1.15.2",

"Microsoft.Kiota.Serialization.Form": "1.14.0",

"Microsoft.Kiota.Serialization.Json": "1.15.2",

"Microsoft.Kiota.Serialization.Multipart": "1.14.0",

"Microsoft.Kiota.Serialization.Text": "1.14.0",

"System.Net.Http.WinHttpHandler": "6.0.0"

},

"Microsoft.Identity.Client/4.66.2": {

"type": "package",

"dependencies": {

"Microsoft.IdentityModel.Abstractions": "6.35.0",

"System.Diagnostics.DiagnosticSource": "6.0.1"

},

In Microsoft.Identity.Client/4.66.2 release note it is mentioned that it will work with “Microsoft.IdentityModel.Abstractions” >= 6.35.0 but in reality it is not.

Please advise me how to fix this error

Outlook
Outlook
A family of Microsoft email and calendar products.
4,213 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,656 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.
11,145 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 55,676 Reputation points
    2024-12-20T16:34:17.5666667+00:00

    Because you have a mismatch in transient dependencies on some packages you're using then the easiest solution is to promote the transient package to a top level dependency. This will resolve the issue. Since this is a NET Framework app then the options for package references to promote transients to top level don't work, I believe. So just add a reference to Microsoft.IdentityModel.Abstractions for the latest version. Your top level dependency will take precedence over any transient dependencies defined by related packages.

    0 comments No comments

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.