Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON config not working with dotnet 8 #514

Open
nsmithdev opened this issue Apr 3, 2024 · 2 comments · May be fixed by #543
Open

JSON config not working with dotnet 8 #514

nsmithdev opened this issue Apr 3, 2024 · 2 comments · May be fixed by #543

Comments

@nsmithdev
Copy link

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

I believe the breaking change below is the cause.
dotnet/docs#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)
@HellGate94
Copy link

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

@jasonla
Copy link

jasonla commented Aug 2, 2024

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.

@Kaaybi Kaaybi linked a pull request Sep 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants