1

I've added a method returning an IAsyncEnumerable<MyClass> to my SignalR hub method. However, instead of an object array, it seems to serialize the IAsyncEnumerable object itself. Right now, the client receives the following object:

{
  "<>1__state": -2,
  "<>t__builder": {},
  "<>v__promiseOfValueOrEnd": {
    "RunContinuationsAsynchronously": false,
    "Version": 0
  },
  "<>3__cargoListID": 13
}

Here's the source code of my hub:

public class CargoListHub : Hub
{
    public IAsyncEnumerable<OrtecDetails> GetOrtecDetails(int cargoListID)
    {
        return OrtecDetails.GetOrtecDetails(cargoListID);
    }
}

public record OrtecDetails
{
   internal static async IAsyncEnumerable<OrtecDetails> GetOrtecDetails(int cargoListID)
   {
       using DatabaseEntities db = new();

       DateTime ortecReferenceDate = await someSql();

       IQueryable<string> allVKOs = someQuery();

       foreach (string vko in allVKOs.Distinct())
       {
           string pathToPDF = GetOrtecPath(vko, ortecReferenceDate);
           yield return CreateFromPDF(pathToPDF);
       }
   }
}

The project is written in .NET Framework 4.8 with SignalR 2.4.3.

How can I fix this?

André Reichelt
  • 1,484
  • 18
  • 52
  • 1
    Can we see your code? – phuzi Jul 07 '22 at 14:27
  • @phuzi I'll add it in a minute.. – André Reichelt Jul 07 '22 at 14:28
  • Having said that, I don't think async streams are available prior to C#8 which requires at least .NET Core 3. [Async Streams in C# 8](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#asynchronous-streams) – phuzi Jul 07 '22 at 14:32
  • @phuzi Any workaround for that? We will eventually move that project to .NET 6 in the next 12 months, so I want to use as many of the new features as possible. My code DOES compile, but the serialization seem to fail. – André Reichelt Jul 07 '22 at 14:35
  • I don't think so, not until you migrate to .Net 6 (7 will be release in November) – phuzi Jul 07 '22 at 15:15

0 Answers0