Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory'
<p>Following is the exact exception I am getting while running my .NET application.</p>

<blockquote>
  <p>An unhandled exception of type 'System.IO.FileNotFoundException'
  occurred in Generic.Helpers.dll</p>
  
  <p>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.</p>
</blockquote>

<p>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 </p>

<pre><code>&lt;package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.1" targetFramework="net46" /&gt;
</code></pre>

<p>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.</p>

<p>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.</p>

<p>I am also consuming the same DLL in Azure function which is where it works perfectly fine.</p>

<p>Can anyone please suggest how to resolve this issue?</p>