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

Notification

Icon
Error

MSTest TestContext CancellationTokenSource null
VNicholson
#1 Posted : Monday, August 25, 2025 10:04:38 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/19/2013(UTC)
Posts: 27
Location: New Zealand

Thanks: 8 times
Was thanked: 4 time(s) in 4 post(s)
Hi,

I updated to the most recent MSTest meta package recently and resolved a number of analyzer warnings, MSTEST0049 being one of them. The suggested fix for that warning is to leverage the TestContext.CancellationTokenSource.Token property when invoking asynchronous methods with cancellation token parameters. The test context injected by NCrunch has a null CancellationTokenSource property however preventing this from being used.

Further to this, the latest documentation from Microsoft suggests constructor injection of the test context being the recommended way of obtaining a test context. NCrunch however requires there to be a parameterless constructor defined, so this approach cannot be used either.

Code:
System.MissingMethodException: Cannot dynamically create an instance of type 'MyTests'. Reason: No parameterless constructor defined.
   at System.RuntimeType.ActivatorCache..ctor(RuntimeType rt)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at nCrunch.TestExecution.Reflection.Clr.ClrType.CreateInstance()
   at nCrunch.Module.MSTest.Integration.MSTestTest.tryCreateFixtureInstance()


I'm aware of the murky nature of the MSTest emulation in NCrunch, but are either of these issues something that can be addressed?

NCrunch 5.16.0.5 in Visual Studio by the way.
Remco
#2 Posted : Tuesday, August 26, 2025 3:41:02 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 994 times
Was thanked: 1337 time(s) in 1240 post(s)
Hi, thanks for sharing this issue.

I'll need to make some adjustments to NCrunch's adapter to align it with these changes. Hopefully it's straightforward. I recommend staying on an earlier version of MSTest until we're back in alignment. I'll let you know when I have a build available you can try.
Remco
#3 Posted : Tuesday, August 26, 2025 8:00:14 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 994 times
Was thanked: 1337 time(s) in 1240 post(s)
1 user thanked Remco for this useful post.
VNicholson on 8/26/2025(UTC)
VNicholson
#4 Posted : Tuesday, August 26, 2025 8:12:41 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/19/2013(UTC)
Posts: 27
Location: New Zealand

Thanks: 8 times
Was thanked: 4 time(s) in 4 post(s)
[quote=Remco;18289]Would you be interested in trying the build below to see if this meets your needs better?

I retested the TestContext constructor injection and property injection test cases and both worked with those new builds. Thanks so much for the insanely fast turn around.
1 user thanked VNicholson for this useful post.
Remco on 8/26/2025(UTC)
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.029 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download