Skip to content

JsonException when generating Id on Alpine Linux #63

Description

@corentinbst

Hello,
I am facing an issue generating a device id that happens only on Alpine Linux. The specific context is a docker container using the official dotnet/sdk:7.0-alpine image. On Windows and on my Ubuntu container everything runs fine.

The code used to generate the machine ID is this one:

new DeviceIdBuilder()
        .AddMacAddress(true)
        .OnWindows(windows => windows
            .AddProcessorId()
            .AddMotherboardSerialNumber()
            .AddSystemDriveSerialNumber())
        .OnLinux(linux => linux
            .AddCpuInfo()
            .AddMotherboardSerialNumber()
            .AddSystemDriveSerialNumber())
        .ToString()

And the error I'm getting is this one:

System.TypeInitializationException : The type initializer for 'XXX.Common.Utilities.Security.Device' threw an exception.
---- System.Text.Json.JsonException : The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
-------- System.Text.Json.JsonReaderException : The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
  Stack Trace:
     at XXX.Common.Utilities.Security.Device.get_Id() in /builds/XXX/common/Utilities/Security/Device.cs:line 17
   at XXX.Common.Test.Utilities.Security.DeviceTests.Id() in /builds/XXX/common/Test/Utilities/Security/Device.cs:line 20
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
----- Inner Stack Trace -----
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
   at DeviceId.Linux.Components.LinuxRootDriveSerialNumberDeviceIdComponent.GetValue()
   at DeviceId.Formatters.HashDeviceIdFormatter.<>c.<GetDeviceId>b__4_1(KeyValuePair`2 x)
   at System.Linq.Enumerable.SelectIPartitionIterator`2.PreallocatingToArray(Int32 count)
   at System.Linq.Enumerable.SelectIPartitionIterator`2.ToArray()
   at DeviceId.Formatters.HashDeviceIdFormatter.GetDeviceId(IDictionary`2 components)
   at DeviceId.DeviceIdBuilder.ToString()
   at XXX.Common.Utilities.Security.Device..cctor() in /builds/XXX/common/Utilities/Security/Device.cs:line 17
----- Inner Stack Trace -----
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)

I would appreciate any feedback even if it's that alpine linux is not supported. Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions