0
 foreach (var user in userIdentifiers) { 
var response = await client.sendMsgAsync(
                              accesscode: paswoord,
                              userIdentifier: user,
                              title: "Lovapaanvraag",
                              body: "Zie .pdf bijlage voor uitgebreide informatie",
                              senderIdentifier: senderIdentifier,
                              attachments: jsonString,
                              coaccount: 0,
                              copyToLVS: false);

  int resultaat = Convert.ToInt32(response);
  if (resultaat != 0) geslaagd = false;      }

We are working in Blazor wasm. After filling in a form, an entity gets created and added into the db. After that a .pdf gets created from the form and gets submitted to an external messaging-platform. This messagingservice calls the above client.SendMsgAsync(). client.SendMsgAsync() is defined on an api we don't control. It's a given in this context. When successful it returns an object-type which contains a 0.

When placing the messagingservice in a different project, I was able to unit-test it. It works.

When running directly in Blazor wasm I get the following error:

System.PlatformNotSupportedException: Cannot wait on monitors on this runtime.

There definetely is information about this issue out there. If I understand it well, it's a thread (blocking) issue.

In the end I have to be able to I suggest you extract the async work out of the sync code path and cache the results for use within the sync path.. Someone else put it as, I somehow need to get rid of the await.

Task.WhenAll() basically only displaces the issue (and provokes loss of information). So I'm quite at a loss how to solve this problem, that shouldn't be so difficult.

I don't feel the Task.Delay()-suggestions are relevant in this, as they are more linked the with UI-thread, and event-handling outside of the LifeCycle. But Task.Delay() didn't seem the work anyway.

Any suggestions, or new leads, would be greatly appreciated.

Update

The person who answered the question in the comments, Mr. Henk Holterman, also closed it referring to a previous question and answer (also by him). I'm not sure I agree there. I actually read that question before asking mine, and how I interpreted that was: "you need to rewrite the code so you'll get rid of the wait's". Here the answer is: it can't be done in the blazor wasm, because the service you're calling holds a lock, and blazor wasm doesn't know how to deal with that. The first answer gives an incentive to rework/rewrite, the latter to go look for an alternative. Or in other words, if I had encountered this paragraph there, I would not have asked my question, I would have considered it resolved.

Finally, as a token of appreciation, i've upvoted the answer there.

8
  • 1
    That API apparently uses Threads an lock() and is therefore not compatible with Blazor. You appear to have a backend, that is the better place to call this. Commented Jun 28 at 19:40
  • Oh boy. I had this on my list of worst case alternative scenario's. LOL. Commented Jun 28 at 19:45
  • But it makes sense. Sometimes it's just good to know you can quit looking in a certain place for a solution. Commented Jun 28 at 19:45
  • 1
    I would expect that somethiong like a password is required. You don't want that in Wasm either. Commented Jun 28 at 19:47
  • 1
    This has been asked several times, the core answer is PlatformNotSupported Exception Commented Jun 28 at 21:18

0

Browse other questions tagged or ask your own question.