Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

The current SynchronizationContext may not be used as a TaskScheduler.
tofutim
#1 Posted : Friday, January 3, 2014 9:23:53 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/27/2012(UTC)
Posts: 19
Location: California

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
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?
Remco
#2 Posted : Friday, January 3, 2014 10:43:39 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
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.
rold2007
#3 Posted : Saturday, January 11, 2014 4:16:20 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/19/2012(UTC)
Posts: 2
Location: New Caledonia

Thanks: 1 times
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...-used-as-a-taskscheduler
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.028 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download