Following is the exact exception I am getting while running my .NET application.
An unhandled exception of type 'System.IO.FileNotFoundException'
occurred in Generic.Helpers.dll
Additional information: Could not load file or assembly
'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.1.741,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The system cannot find the file specified.
I have a console application which references a private assembly (.dll). The assembly is referencing to Microsoft.IdentityModel.Clients.ActiveDirectory, and I have also added a NuGet package for this in the project
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.1" targetFramework="net46" />
I can see the DLLs are being referenced correctly in the project. However, while running the application, I am getting an error as mentioned above.
Just to give you a brief overview of the class library project - this DLL has methods to connect to CRM web api. This was working fine until last few days, and suddenly stopped working and throwing the error.
I am also consuming the same DLL in Azure function which is where it works perfectly fine.
Can anyone please suggest how to resolve this issue?
May be you don't have that specific version? have you tried setting specific version to false in properties?
NuGet won't handle the references in the program. It just manages packages. This issue is with visual studio. If NuGet updates some packages and your program asks for specific version, you will definitely get problems.
This was my situation and what worked for me:
I was using the Microsoft.IdentityModel.Clients.ActiveDirectory
version 3.19 in a class library project but only had version 2.22 installed in the actual ASP.NET Web Application project. Upgrading to 3.19 in the web app project got me past the error.
This happened with me when I downgraded my dll to version 2.28.3 from 3.19 to support "AcquireTokenByAuthorizationCode" functionality. After reinstallation it was still redirecting to version 3.19 because it was still binded to version 3.19 in web.config file. I did find all search for 3.19 with . file type and commented the setting which was referring 3.19. like one in web.config below
<!--<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.19.8.16603" newVersion="3.19.8.16603" />
</dependentAssembly>-->
This happens when nuget package versions are not same across all projects in the solution.
Solution->Nuget Package manager-> browse for package
If there are different versions, make them uniform across projects. Issue should be solved.