Skip to content

Using System.DirectoryServices on a Windows container with ASP.NET Core returns an error #1767

Description

@joseotavioq

Steps to reproduce the issue

  1. Create an ASP.NET Core Application;
  2. Add a reference to the Nuget package "System.DirectoryServices" (Version: 4.7.0) and use it (as an example below);
  3. Create a Docker Image from the Windows image "mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903";
  4. Execute a docker run on the created image and access the page that uses the DirectoryServices package.

Code Example:

public string Find(string Name)
{
    using (DirectoryEntry entry = new DirectoryEntry("LDAP://xxxxx"))
    {
        using (var searcher = new DirectorySearcher(entry, "userPrincipalName=" + Name))
        {
            var results = searcher.FindOne();
            return results.GetDirectoryEntry().Properties["blabla"].Value.ToString();
        }
    }
}

Expected behavior

Execute without error.

Actual behavior

Received an error:

System.DllNotFoundException: Unable to load DLL 'activeds.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
   at System.DirectoryServices.Interop.UnsafeNativeMethods.IntADsOpenObject(String path, String userName, String password, Int32 flags, Guid& iid, Object& ppObject)
   at System.DirectoryServices.Interop.UnsafeNativeMethods.ADsOpenObject(String path, String userName, String password, Int32 flags, Guid& iid, Object& ppObject)
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
   at System.DirectoryServices.DirectorySearcher.FindOne()
   at WebAppTest.LdapHelper.Find(String Name)
   at WebAppTest.Controllers.HomeController.Index()

Additional information (e.g. issue happens only occasionally)

It works if I execute dotnet run on my Windows 10 machine.

Output of docker version

Docker version 19.03.8, build afacb8b

Output of docker info

Client:
 Debug Mode: false
 Plugins:
  app: Docker Application (Docker Inc., v0.8.0)
  buildx: Build with BuildKit (Docker Inc., v0.3.1-tp-docker)

Server:
 Containers: 3
  Running: 0
  Paused: 0
  Stopped: 3
 Images: 13
 Server Version: 19.03.8
 Storage Driver: windowsfilter
  Windows:
 Logging Driver: json-file
 Plugins:
  Volume: local
  Network: ics internal l2bridge l2tunnel nat null overlay private transparent
  Log: awslogs etwlogs fluentd gcplogs gelf json-file local logentries splunk syslog
 Swarm: inactive
 Default Isolation: hyperv
 Kernel Version: 10.0 18363 (18362.1.amd64fre.19h1_release.190318-1202)
 Operating System: Windows 10 Enterprise Version 1909 (OS Build 18363.720)
 OSType: windows
 Architecture: x86_64
 CPUs: 8
 Total Memory: 31.82GiB
 Name: XXXXXX
 ID: IO6O:IH6H:FD7H:4YZ4:63ID:AE6L:4DAB:5DDV:672I:SAAH:GGAF:GJ5G
 Docker Root Dir: C:\ProgramData\Docker
 Debug Mode: true
  File Descriptors: -1
  Goroutines: 28
  System Time: 2020-03-25T12:18:00.5479762-03:00
  EventsListeners: 1
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions