In testing async methods, sometimes I add in to such issues:
System.InvalidOperationException : The current SynchronizationContext may not be used as a TaskScheduler.
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Loqu8.Dict.BaseDict.<Init>d__0.MoveNext() in \\vmware-host\Shared Folders\Documents\Projects\Loqu8\kumquat\src\Loqu8\Dict\Loqu8.Dict\BaseDict.cs:line 441#0
In the past I have used
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
in the Setup, but sometimes even this doesn't work. Any ideas?
Build/Test Issues
The current SynchronizationContext may not be used as a TaskScheduler.
Started by tofutim on 10,452 views
Remco NCrunch Developer
#5011
03 Jan 2014 22:43 UTC
Hi, thanks for sharing this issue.
NCrunch doesn't perform any special actions on the SynchronizationContext. Can you share any details around which test framework you are using? Do you also experience this problem with any test runner other than NCrunch?
NCrunch can introduce a different execution order for your tests. Because most other test runners don't do this, the change in order can sometimes cause tests to fail intermittently if they are state dependent. It's difficult for me to suggest with any certainty whether this is causing your problem, but I thought I'd mention it as worth a look, since it can be a common cause for similar sounding issues.
NCrunch doesn't perform any special actions on the SynchronizationContext. Can you share any details around which test framework you are using? Do you also experience this problem with any test runner other than NCrunch?
NCrunch can introduce a different execution order for your tests. Because most other test runners don't do this, the change in order can sometimes cause tests to fail intermittently if they are state dependent. It's difficult for me to suggest with any certainty whether this is causing your problem, but I thought I'd mention it as worth a look, since it can be a common cause for similar sounding issues.
I just had the same problem using NCrunch 2.2.0.2 and I resolved it by calling SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()) as seen on this question
http://stackoverflow.com/questions/8245926/the-current-synchronizationcontext-may-not-be-used-as-a-taskscheduler
http://stackoverflow.com/questions/8245926/the-current-synchronizationcontext-may-not-be-used-as-a-taskscheduler
Post a reply
Log in to reply.