private async Task<string> getDeviceDescription(int manufacture, string serialNu
ID: 3907972 • Letter: P
Question
private async Task<string> getDeviceDescription(int manufacture, string serialNumber)
{
var output = new sqlParameter("@deviceDescription", sqlDbType.NVarChar, 255) { Direction = ParameterDirection. Output };
await Database.ExecuteSqlCommandAsync("exec storedProcedure @manufacture, @serialNumber, @deviceDescription OUT", new sqlParameter("@manufacture", manufacture), new sqlParameter("@serialNumber", serialNumber), output);
description = (string) output.Value;
return description;
}
I keep getting System.AggregateException: One or more errors occurred. ---> System.NotSupportedException: A second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. Any instance members are not guaranteed to be thread safe.
Explanation / Answer
Hi Sir, the solution to your problem is this:-
You can inherit from your AppServiceBase and disable UOW for your method:
[UnitOfWork(IsDisabled = true)]
private async Task<string> getDeviceDescription(int manufacture, string serialNumber)
{
//...
}
By this you, I am sure you wont encounter the exception. Also a good suggestion will be to use a handler to investigate more on the error by adding a try catch block as mentioned below:-
Please let me know in case of any clarifications required. Thanks!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.