question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when serializing IAsyncEnumerable in .NET 6

See original GitHub issue

I’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:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Tornhoofcommented, Nov 17, 2021

Okay, you still return IAsnycEnumerable, I was confused as you wrote about Ienumerable in between. As I previously said, this can’t work properly.

0reactions
silkfirecommented, Nov 17, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found