I have a LOT of problems using async query methods on the server.
I get random exception or strange behavior while having 4 queries in // awaited in a Task.WhenAll.
so far I got in my main application those random Exception (can happen once every 10 or more exceutions) while awaiting Task.WhenAll() :
- "Execution of query against the server was successful but execution of query against the local cache failed"
- "Object reference not set to an instance of an object"
- another one about the collection changed during an enumeration
I also have a query returning 0 entity while it should ALWAYS return 1 entity (query part of the WhenAll).
If I execute the exact same query right after the WhenAll but withouth the Async method (standard ToList()), the query return the expected entity !!
As for the exception above, this is a random behavior.
private static async void TestMothodWithAsync() { var em = new NorthwindIBEntities(); em.AuthorizedThreadId = null; for (var bcl = 1; bcl <= 1000; bcl++) { em.Clear(); Console.WriteLine("Iteration {0}", bcl);
var tskOrder = new EntityQuery<Order>().With(em).ExecuteAsync(); var tskRegion = new EntityQuery<Region>().With(em).ExecuteAsync(); var tskCategory = new EntityQuery<Category>().With(em).ExecuteAsync(); var tskTerritory = new EntityQuery<Territory>().With(em).ExecuteAsync();
await Task.WhenAll(tskOrder, tskRegion, tskCategory, tskTerritory); } Console.WriteLine("Done."); Console.ReadLine(); }
|
When I execute the console application, it will throw an Exception "Object reference not set to an instance of an object" on a random iteration (can be at iteration 1 or as late as at iteration 200).
Note : I didn't get the others kind of exception in the test project.
Am I doing something wrong ?
Below the trace of the Exception :
System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
à IdeaBlade.EntityModel.EntityManager.<FireQueuedEvents>b__f9(Action a)
à System.Collections.Generic.List`1.ForEach(Action`1 action)
à IdeaBlade.EntityModel.EntityManager.FireQueuedEvents()
à IdeaBlade.EntityModel.EntityManager.LoadingBlock.Dispose()
à IdeaBlade.EntityModel.EntityQueryResultCollection..ctor(DataQueryResultCollection dqResults, EntityManager entityManager, MergeStrategy mergeStrategy)
à IdeaBlade.EntityModel.EntityManager.MergeAndReturnUsingCache(IEntityFinder finder, DataQueryResultCollection dqResults)
à IdeaBlade.EntityModel.EntityManager.ProcessFetchedData(DataQueryResultCollection dqResults, IEntityFinder finder)
à IdeaBlade.EntityModel.EntityManager.<ExecuteFetchAsync>d__c1.MoveNext()
--- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée ---
à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
à System.Runtime.CompilerServices.TaskAwaiter.GetResult()
à IdeaBlade.EntityModel.EntityQueryFinder.<ExecuteAsync>d__0.MoveNext()
--- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée ---
à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
à System.Runtime.CompilerServices.TaskAwaiter.GetResult()
à IdeaBlade.EntityModel.EntityManager.<ExecuteQueryAsyncCore>d__69.MoveNext()
--- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée ---
à System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
à System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
à System.Runtime.CompilerServices.TaskAwaiter.GetResult()