System.IO.FileNotFoundException: 'Could not load file or assembly

Anjali Agarwal 1,531 Reputation points
2023-03-02T18:25:05.9533333+00:00

I have an application in .net core. the application was running fine, but the error started coming after I installed

dotnet add package Microsoft.AspNetCore.Authentication.Negotiate --version 6.0.14

Once I installed this package and put this line of code in startup.cs file:

services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)

       .AddNegotiate();

    services.AddAuthorization(options =>

    {

        options.FallbackPolicy = options.DefaultPolicy;

    });

I started getting this error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.DirectoryServices.Protocols, Version=6.0.0.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'

I installed this package when I saw the above error:

dotnet add package System.DirectoryServices --version 7.0.0

I am still getting this error. The error is coming in program.cs file. below is the screen shot of the error:

User's image

unfortunately, I dont see version 6.0.0.1 for System.directoryServices.protocols in nuget. Not sure, why the application is looking for 6.0.0.1 version when I have 7.0.0 version installed. Below is packages installed on my application:

User's image

Developer technologies ASP.NET ASP.NET Core
Developer technologies ASP.NET Other
{count} vote

Accepted answer
  1. Anonymous
    2023-03-03T02:07:57.98+00:00

    Hi @Anjali Agarwal

    Can you tell us your application type and version? Whether it is an Asp.net 6 MVC or Razor page application?

    I create an Asp.net 6 MVC application to check it, after installing the "Microsoft.AspNetCore.Authentication.Negotiate 6.0.14" package, it will auto install the "System.DirectoryServices.Protocols 6.0.1" package, and after configuring the Negotiate authentication, your code works well without any error.

    When installs the "Microsoft.AspNetCore.Authentication.Negotiate 6.0.14" package via NuGet, we can see its dependencies is: .Net 6.0 and "System.DirectoryServices.Protocols 6.0.1". After installing the Negotiate package via NuGet, it will also install the "System.DirectoryServices.Protocols 6.0.1".

    User's image

    So, you can try to re-install the Microsoft.AspNetCore.Authentication.Negotiate 6.0.14 package via NuGet.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion

    2 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Darin Milligan 10 Reputation points
    2023-03-14T20:36:10.42+00:00

    The problem I have is that I am referencing System.DirectoryServices and System.DirectoryServices.AccountManagement in a library project that my web project uses.

    If I try and set the version of these packages in the library project to anything other than 6.0.1 and 6.0.0 respectively I get the same error. Note that when I set these to 7.0.1 and 7.0.0 in the library project, the version of System.DirectoryServices.Protocols displayed as a dependency of Microsoft.AspNetCore.Authentication.Negotiate is no longer 6.0.1 but rather 7.0.0 and I get the error message.

    I think somehow the Microsoft.AspNetCore.Authentication.Negoitiate package is not working with the 7.0.0 System.DirectoryServices package or it's wanting the earlier version but not getting it as a dependency since the solution is having a newer version via the library references.

    1 person found this answer helpful.

  2. LeonardoFucci-4004 30 Reputation points
    2025-05-26T14:14:41.4966667+00:00

    In case you find this issue while trying to test in your deployed (published) environment, the issue in my case, was related to this setting you can specify while the publish is configured, the one that says "Trim Unused Code".

    I guess I have the reference there but used with an Activator... idk... for some reason the publish determines it needs to trim this library. Set the checkbox in false and solved my problem.

    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.