dotnet / Docker.DotNet

:whale: .NET (C#) Client Library for Docker API
https://www.nuget.org/packages/Docker.DotNet/
MIT License
2.23k stars 381 forks source link

NullReference Error in ListContainersAsync #679

Closed Davidcc closed 2 months ago

Davidcc commented 2 months ago

Output of dotnet --info:

.NET SDK:
 Version:           8.0.300
 Commit:            326f6e68b2
 Workload version:  8.0.300-manifests.4e5ea2d8
 MSBuild version:   17.10.4+10fbfbf2e

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.300\

.NET workloads installed:
 [aspire]
   Installation Source: VS 17.10.34916.146
   Manifest Version:    8.0.0/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.0.0\WorkloadManifest.json
   Install Type:        FileBased

Host:
  Version:      8.0.5
  Architecture: x64
  Commit:       087e15321b

.NET SDKs installed:
  2.2.207 [C:\Program Files\dotnet\sdk]
  5.0.411 [C:\Program Files\dotnet\sdk]
  8.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

What version of Docker.DotNet?: 3.125.15

(paste your output here)

Steps to reproduce the issue: 1.delete all containers using Docker Desktop 2.create client: DockerClient client = new DockerClientConfiguration(new Uri("tcp://localhost:2375")).CreateClient(); 3.attempt to get lit of containers var containers = await client.Containers.ListContainersAsync(new ContainersListParameters { All = true // Include stopped containers in the list });

What actually happened?: error thrown: Category: OBSStartupService.Worker EventId: 0 Queues Startup error: Object reference not set to an instance of an object. Exception: System.NullReferenceException: Object reference not set to an instance of an object. at Docker.DotNet.QueryString1.<>c__132.b__13_0(PropertyInfo p) at System.Linq.Enumerable.WhereArrayIterator1.MoveNext() at System.Linq.Enumerable.<Any>g__WithEnumerator|36_0[TSource](IEnumerable1) at System.Linq.Enumerable.AnyTSource at Docker.DotNet.QueryString1.FindAttributedPublicProperties[TValue,TAttribType]() at Docker.DotNet.QueryString1..ctor(T) at Docker.DotNet.ContainerOperations.ListContainersAsync(ContainersListParameters, CancellationToken ) at OBSStartupService.Services.QueueStartupService.GetContainerByName(DockerClient, String) at OBSStartupService.Services.QueueStartupService.GetOrCreateContainer(DockerClient, String) at OBSStartupService.Services.QueueStartupService.StartContainer(DockerClient) at OBSStartupService.Services.QueueStartupService.StartQueues() at OBSStartupService.Worker.ExecuteAsync(CancellationToken)

What did you expect to happen?: an empty list of containers would be returned

Additional information: when running in debug in VS 2022, it works as expected. When deployed to a test environment (windows 11 azure VM), and installed as a windows service like: sc.exe create "Omedus Base Station Startup Service" binpath= "C:\Omedus\OBSStartupService.exe"

it throws the above error.

dotnet --info from the test PC is shown below

Host: Version: 8.0.5 Architecture: x64 Commit: 087e15321b RID: win-x64

.NET SDKs installed: No SDKs were found.

.NET runtimes installed: Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Davidcc commented 2 months ago

I changed compile options to not "trim unused code" and now it all works fine.

Davidcc commented 2 months ago

I changed compile options to not "trim unused code" and now it all works fine.