Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joseotavioq opened this issue Mar 25, 2020 · 3 comments

Comments

@joseotavioq
Copy link

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
@MichaelSimons
Copy link
Member

This looks like a potential limitation with Nano Server. My suggestion is to try this scenario using a Windows Server Core image. Checkout out our guidance for how to create your own .NET image based on Windows Server Core.

@MichaelSimons
Copy link
Member

Closing, There is an open issue for this System.DirectoryService limitation on Nano Server.

@joseotavioq
Copy link
Author

Only to update this.
I created another Dockerfile using the Server Core image with IIS and installed the AspNetCore 3.1.0 and the ASP.NET Core 3.1 Runtime (v3.1.3) - Windows Hosting Bundle and it works.

Here is the Dockerfile

FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-1909

RUN powershell -NoProfile -Command \
    $ErrorActionPreference = 'Stop'; \
    $ProgressPreference = 'SilentlyContinue'; \
    Invoke-WebRequest -UseBasicParsing -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1; \
    ./dotnet-install.ps1 -InstallDir '/Program Files/dotnet' -Runtime aspnetcore -Version 3.1.0; \
    Remove-Item -Force dotnet-install.ps1; \
    setx /M PATH '%PATH%;C:/Program Files/dotnet'

RUN powershell -NoProfile -Command \
    Invoke-WebRequest -UseBasicParsing -Uri https://download.visualstudio.microsoft.com/download/pr/ff658e5a-c017-4a63-9ffe-e53865963848/15875eef1f0b8e25974846e4a4518135/dotnet-hosting-3.1.3-win.exe -OutFile dotnet-hosting.exe; \
    $process = Start-Process -Filepath dotnet-hosting.exe -ArgumentList  @('/install', '/q', '/norestart', 'OPT_NO_RUNTIME=1', 'OPT_NO_SHAREDFX=1') -Wait -PassThru; \
    if ($process.ExitCode -ne 0) { exit $process.ExitCode; } \
    Remove-Item -Force dotnet-hosting.exe

RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*

WORKDIR /inetpub/wwwroot

COPY Deploy .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants