FFMpegCore icon indicating copy to clipboard operation
FFMpegCore copied to clipboard

JSON config not working with dotnet 8

Open nsmithdev opened this issue 11 months ago • 2 comments

I'm having a problem with using json config file and dotnet 8.

I believe the breaking change below is the cause. https://github.com/dotnet/docs/issues/37041

Stack trace from error.

System.InvalidOperationException: The type 'System.ReadOnlySpan`1[System.Byte]' of property 'Preamble' on type 'System.Text.Encoding' is invalid for serialization or deserialization because it is a pointer type, is a ref struct, or contains generic parameters that have not been replaced by specific types.
   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_CannotSerializeInvalidType(Type typeToConvert, Type declaringType, MemberInfo memberInfo)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreatePropertyInfo(JsonTypeInfo typeInfo, Type typeToConvert, MemberInfo memberInfo, JsonSerializerOptions options, Boolean shouldCheckForRequiredKeyword, Boolean hasJsonIncludeAttribute)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.AddMembersDeclaredBySuperType(JsonTypeInfo typeInfo, Type currentType, Boolean constructorHasSetsRequiredMembersAttribute, PropertyHierarchyResolutionState& state)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulateProperties(JsonTypeInfo typeInfo)
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateTypeInfoCore(Type type, JsonConverter converter, JsonSerializerOptions options)     
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type type)      
   at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context)
--- End of stack trace from previous location ---
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()        
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()  
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()
--- End of stack trace from previous location ---
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
   at FFMpegCore.GlobalFFOptions.LoadFFOptions()
   at FFMpegCore.GlobalFFOptions.get_Current()
   at FFMpegCore.FFProbe.AnalyseAsync(String filePath, FFOptions ffOptions, CancellationToken cancellationToken)

nsmithdev avatar Apr 03 '24 21:04 nsmithdev

same issue here as well. however i still have this issue when downgrading to .net7

HellGate94 avatar Apr 04 '24 12:04 HellGate94

Yeah, had the same exception. When debugging through IIS Express in VS2022, it worked fine. But when running through IIS, the exception showed up. The issue comes from a change in .NET 8 JsonSerializer. When FFMpregCore tries to read from the JSON config file and deserialize the the FFOptions.Encoding variable, this is where the error happens.

My work around is to pass the options into the method call instead of reyling on the JSON config file.

To be clear: Instead of: having a ffmpeg.config.json, you'd delete / stop using ffmpeg.config.json.

Do this:

 var ffOptions = new FFOptions
 {
    BinaryFolder = "./binaries", // or where ever you put your binaries
    TemporaryFilesFolder = "./tmp",
    Encoding = Encoding.Default // Or whatever encoding you want
 };

var probeData = await FFProbe.AnalyseAsync(@"C:\media\movie1.mkv", ffOptions, cancellationToken);

This allowed the process to work.

jasonla avatar Aug 02 '24 03:08 jasonla