Error when serializing IAsyncEnumerable in .NET 6
See original GitHub issueI’ve had a piece of code that serializes an IAsyncEnumerable
since this type was introduced in .NET Core 3.1 and it’s been working great together with SpanJson.
Recently, I upgraded to the newly released .NET 6 and after testing my application I got a long stack of errors at the location that serializes this type.
Would you mind checking what’s causing the issue?
ArgumentException: Type 'System.Runtime.InteropServices.StructLayoutAttribute' does not have a default constructor (Parameter 'type')
System.Linq.Expressions.Expression.New(Type type)
SpanJson.Formatters.ComplexFormatter.BuildDeserializeDelegate<T, TSymbol, TResolver>()
SpanJson.Formatters.ComplexClassFormatter<T, TSymbol, TResolver>..cctor()
System.RuntimeFieldHandle.GetValue(RtFieldInfo field, object instance, RuntimeType fieldType, RuntimeType declaringType, ref bool domainInitialized)
System.Reflection.RtFieldInfo.GetValue(object obj)
SpanJson.Resolvers.ResolverBase.GetDefaultOrCreate(Type type)
SpanJson.Resolvers.ResolverBase<TSymbol, TResolver>.BuildFormatter(Type type)
SpanJson.Resolvers.ResolverBase<TSymbol, TResolver>.<GetFormatter>b__3_0(Type x)
System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>.GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)
SpanJson.Resolvers.ResolverBase<TSymbol, TResolver>.GetFormatter(Type type)
SpanJson.Resolvers.ResolverBase<TSymbol, TResolver>.GetFormatter(JsonMemberInfo memberInfo, Type overrideMemberType)
SpanJson.Formatters.ComplexFormatter.BuildSerializeDelegate<T, TSymbol, TResolver>()
SpanJson.Formatters.ComplexClassFormatter<T, TSymbol, TResolver>..cctor()
(The chain of errors is much longer than this but looks very similar to above)
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
System.Text.Json IAsyncEnumerable serialization - .NET
Asynchronous serialization methods now enumerate any IAsyncEnumerable<T> instances in an object graph and then serialize them as JSON arrays ...
Read more >Asynchronous serialization of IAsyncEnumerable class ...
Returning an IAsyncEnumerable from an action no longer buffers the response content in memory before it gets sent. This helps reduce memory ...
Read more >ASP.NET Core 6 and IAsyncEnumerable - Async Streamed ...
NET 6 is support for async streaming of IAsyncEnumerable . In .NET 6, System.Text.Json can serialize incoming IAsyncEnumerable in asynchronous ...
Read more >Developers using JsonSerializer can asynchronously (de) ...
IAsyncEnumerable serialization is only supported via the SerializeAsync method. Invoking the converter via any of the sync Serialize methods ...
Read more >Our failed attempt at IAsyncEnumerable - Ankit Vijay
So, here I'm talking about our failed attempt to migrate to IAsyncEnumerable. Background. With the release of .NET Core 3.1 and .NET Core...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, you still return IAsnycEnumerable, I was confused as you wrote about Ienumerable in between. As I previously said, this can’t work properly.
Just create an ASP.NET Core project with a controller containing an action with the return type
IAsyncEnumerable<>
targeting .NET 6, and you should hit the error as soon as you launch the app.