Closed codingyourlife closed 10 months ago
The Publish
code is very simple but that Wait
in the constructor is a bit worrisome. Don't do any async work in a constructor.
Yes true. Thanks @jbogard !
Right. Async call with .Wait() in constructor causes issues. I cross-posted on Stackoverflow where people linked pages to read about the issue: https://stackoverflow.com/questions/77141268/mediatr-publish-command-stuck-in-combination-with-await-tolistasync.
How I solved it: I created an API endpoint for the admin to trigger the function manually
Hi. I have a strange problem where calling Publish() gets stuck (command never finishes) if it is used in combination with ToListASYNC(). It works with ToList(). I prepared a minimum example. Sadly due to db dependency not a click and run but I think you can get it going quite quick.
I use .NET 6 and ToListAsync() is available via
import Microsoft.EntityFrameworkCore
.I use this nuget package of EntityFrameworkCore and generally this version number:
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" />
For me it doesn't make any sense why ToList() + foreach works but ToListAsync() + foreach doesn't.
MediatR I use v11.0.0 but I also tried v12.1.1. and same result.
<PackageReference Include="MediatR" Version="11.0.0" />
For completeness here also my handler:
Is this known? Is this a bug? A bug where?