Skip to content

Metadata serialization throws ImageKitInvalidDataException #75

@matteo-gregoricchio-deltatre

Description

Hello all,

when uploading an image with Exif Data that contains a FocalLength value, we're receiving an exception of type ImageKitInvalidDataException due to a deserialization type mismatch (it tries to deserialize a Long to an Int64).

Stack Trace:

 ---> System.Text.Json.JsonException: The JSON value could not be converted to System.Nullable`1[System.Int64]. Path: $ | LineNumber: 0 | BytePositionInLine: 3.
 ---> System.FormatException: Either the JSON value is not in a supported format, or is out of bounds for an Int64.
   at System.Text.Json.ThrowHelper.ThrowFormatException(NumericType numericType)
   at System.Text.Json.Utf8JsonReader.GetInt64()
   at System.Text.Json.Serialization.Converters.NullableConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, T& value, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, T& value, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Deserialize(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo`1 jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](JsonElement element, JsonSerializerOptions options)
   at Imagekit.Core.WrappedJsonSerializer.GetNullableStruct[T](JsonElement element, String name) in /home/runner/work/imagekit-dotnet/imagekit-dotnet/src/Imagekit/Core/WrappedJsonSerializer.cs:line 76
   --- End of inner exception stack trace ---
   at Imagekit.Core.WrappedJsonSerializer.GetNullableStruct[T](JsonElement element, String name) in /home/runner/work/imagekit-dotnet/imagekit-dotnet/src/Imagekit/Core/WrappedJsonSerializer.cs:line 80
   at Imagekit.Core.JsonDictionary.GetNullableStruct[T](String key) in /home/runner/work/imagekit-dotnet/imagekit-dotnet/src/Imagekit/Core/JsonDictionary.cs:line 147
   at Imagekit.Models.Files.ExifExif.get_FocalLength() in /home/runner/work/imagekit-dotnet/imagekit-dotnet/src/Imagekit/Models/Files/FileMetadata.cs:line 820

Steps to reproduce

  • upload the attached image to your ImageKit account
  • copy the fileId from Imagekit Backoffice
  • Using .NET10 SDK, save the following code to a .cs file and run it with dotnet run. Replace with your account private key and the fileId the two variables.
#:sdk Microsoft.NET.Sdk.Web
#:package Imagekit@6.*
#:property PublishAot=false

using Imagekit;
using Imagekit.Core;

using var client = new ImageKitClient(
    new ClientOptions
    {
        BaseUrl = "https://api.imagekit.io",
        PrivateKey = "replace-with-your-private-key"
    });

var fileId = "replace-with-your-fileid";

var metadata = await client
.Files
.Metadata
.Get(fileId)
.ConfigureAwait(false);

Console.WriteLine($"Focal Length: {metadata?.Exif?.ExifValue?.FocalLength}");

Test image to use

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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