Skip to content

DeviceId doesn't work in docker for Windows containers. #64

@jo185104

Description

@jo185104

Hello,

we use DeviceId in docker. It works in a Linux container, but not in a Windows container.
You support AddDockerContainerId for DeviceId.Linux in the README file. Do you also support Windows containers?

I found the problem where it fails is on this line:

var systemLogicalDiskDeviceId = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 2);

Environment.SpecialFolder.System returns "System"
Environment.GetFolderPath(Environment.SpecialFolder.System) returns an empty string so Substring(0, 2) fails.

Failure with this code:

string deviceId = new DeviceIdBuilder()
    .OnWindows(windows => windows
        .AddProcessorId()
        .AddMotherboardSerialNumber()
        .AddSystemDriveSerialNumber()
        .AddSystemUuid())
    .OnLinux(linux => linux
        .AddCpuInfo()
        .AddMotherboardSerialNumber()
        .AddSystemDriveSerialNumber()
        .AddMachineId())
    .AddFileToken(TokenFilePath)
    .AddMachineName()
    .ToString();

Stack Trace:

at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length) in /_/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs:line 1878\r\n   
at System.String.Substring(Int32 startIndex, Int32 length) in /_/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs:line 1852\r\n  
at DeviceId.Windows.Wmi.Components.WmiSystemDriveSerialNumberDeviceIdComponent.GetValue() in /_/src/DeviceId.Windows.Wmi/Components/WmiSystemDriveSerialNumberDeviceIdComponent.cs:line 23\r\n
at DeviceId.Formatters.HashDeviceIdFormatter.<>c.<GetDeviceId>b__3_1(KeyValuePair`2 x) in /_/src/DeviceId/Formatters/HashDeviceIdFormatter.cs:line 47\r\n  
at System.Linq.Enumerable.SelectIPartitionIterator`2.PreallocatingToArray(Int32 count) in /_/src/libraries/System.Linq/src/System/Linq/Select.SpeedOpt.cs:line 606\r\n  
at System.Linq.Enumerable.SelectIPartitionIterator`2.ToArray() in /_/src/libraries/System.Linq/src/System/Linq/Select.SpeedOpt.cs:line 620\r\n   
at DeviceId.Formatters.HashDeviceIdFormatter.GetDeviceId(IDictionary`2 components) in /_/src/DeviceId/Formatters/HashDeviceIdFormatter.cs:line 47\r\n   
at DeviceId.DeviceIdBuilder.ToString() in /_/src/DeviceId/DeviceIdBuilder.cs:line 54\r\n  

Probably the same problem here:

var systemLogicalDiskDeviceId = Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0, 2);

Thank you in advance for your feedback.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions