You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way exceptions are propagated from back-end to the front end doesn't work with Blazor or any environment that doesn't have awaitable tasks (because they are single-threaded and don't have task completion sources that can be awaited while the task is executing on another thread).
The void ProcessAppException(HttpResponseMessage exception) in AppException contains this:
Cannot wait on monitors on this runtime.
at System.Threading.Monitor.ObjWait(Boolean exitContext, Int32 millisecondsTimeout, Object obj)
at System.Threading.Monitor.Wait(Object obj, Int32 millisecondsTimeout, Boolean exitContext)
at System.Threading.Monitor.Wait(Object obj, Int32 millisecondsTimeout)
at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.SpinThenBlockingWait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.InternalWaitCore(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.InternalWait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task1[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Result()
at Arc4u.AppException.ProcessAppException(HttpResponseMessage exception)
The first versions of Blazor did not throw an exception, but just blocked.
The easiest solution is to add the following in the openApiToCSharpClient section of the facade.nswag and interface.nswag files:
This will make the partial methods in the generated client asynchronous.
The method in Arc4u becomes:
publicstaticasyncTaskProcessAppExceptionAsync(HttpResponseMessageexception,CancellationTokencancellationToken){varcontent=awaitexception.Content.ReadAsStringAsync(cancellationToken);IEnumerable<Message>messages;try{messages=JsonConvert.DeserializeObject<IEnumerable<Message>>(content);}catch{// transform the old format to new one. THIS IS NOT THE WAY TO DO IT, BUT IT IS NOT THE SUBJECT OF THIS ISSUE!!!content=content.Replace("\"Category\":\"Described\"","\"Category\":\"Business\"");content=content.Replace("\"Category\":\"Undescribed\"","\"Category\":\"Technical\"");messages=JsonConvert.DeserializeObject<IEnumerable<Message>>(content);}thrownewAppException(messages);}
Once this is done, the generated code for the partial methods becomes:
TheFacadeOrInterfaceClient.ProcessExceptionAsync=async(response,cancellationToken)=>{if(response.StatusCode==System.Net.HttpStatusCode.BadRequest){awaitAppException.ProcessAppExceptionAsync(response,cancellationToken);}// Add any other specific HttpStatusCode specific to your client.};
This is somewhat related to #37 , which describes the general exception handling problem,
The text was updated successfully, but these errors were encountered:
The way exceptions are propagated from back-end to the front end doesn't work with Blazor or any environment that doesn't have awaitable tasks (because they are single-threaded and don't have task completion sources that can be awaited while the task is executing on another thread).
The
void ProcessAppException(HttpResponseMessage exception)
inAppException
contains this:In Blazor, this will fail at runtime with:
The first versions of Blazor did not throw an exception, but just blocked.
The easiest solution is to add the following in the
openApiToCSharpClient
section of thefacade.nswag
andinterface.nswag
files:This will make the partial methods in the generated client asynchronous.
The method in Arc4u becomes:
Once this is done, the generated code for the partial methods becomes:
This is somewhat related to #37 , which describes the general exception handling problem,
The text was updated successfully, but these errors were encountered: