skip to Main Content

Have an ASP.NET Core Kestrel based web API in which everything works fine when being xcopied from release to intended working directory. But when activating Windows Authentication with Microsoft.AspNetCore.Authentication.Negotiate package, I get a

Could not load file or assembly ‘System.DirectoryServices.Protocols, Version=6.0.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

exception after copying the content from release to the intended working directory and firing the executable (app.Run() in program.cs is the crashing instruction).

The assembly in question is a direct dependency of Microsoft.AspNetCore.Authentication.Negotiate package, and among the files in release and in the working directory there is a System.DirectoryServices.Protocols.dll. Whats wrong?

OS is Windows Server 2019, VS 2022 builds into /release, VS 2022 post build event copies files.

Minimal sample here: https://github.com/olaflischke/WebApiWithAuth

2

Answers


  1. Chosen as BEST ANSWER

    Problem is: The nuget dependencies go to some subfolder /runtime within the /release folder and are referenced there.

    1. Solution: Include that /runtime folder in the copy script. Disadvantage: You are copying subfolders for linux and osx which you probably never will need when you're going to deploy to windows only.

    2. Solution: Don't use nuget. Copy the required assemblies (here: Microsoft.AspNetCore.Authentication.Negotiate.dll and System.DirectoryServices.Protocols.dll) to your solution folder, reference them and set their "Copy to Output Directory" property to "Always". Delete the nuget references from your solution. Disadvantage: No updates by nuget mechanisms.

    Further suggestions highly appreciated!


  2. I had the same problem. In my case, downgrading System.DirectoryServices.AccountManagement from the version 7.0 to 6.0 has solved it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search