I'm getting a strange exception in nCrunch 2.5.0.12. I have a test method and if I change it to use async (it makes an async call) then it fails with this exception while running it:
System.NullReferenceException: Object reference not set to an instance of an object.
at nCrunch.Reflection.Clr.ClrMethod.Invoke(Object instance, Object[] parameters)
And this is the detailed log from nCrunch: Detailed log
The method actually executes, the exception happens after the method is completed.
If I remove the async/await (and just add .Result, as a test) then it runs fine. But I still need to call this with async/await on other (also failing) methods so I can properly catch for exceptions (instead of AggregateException).
NCrunch's MSTest runner doesn't support execution of 'async void' tests, because the behaviour is itself modeled off MSTest, which won't recognise 'async void' tests.
Ahh, mistake on my end, I didn't mean to have these as void, I just forgot to change them to Task (they were sync from the beginning) and I was thrown off by the error. Could we perhaps have a more meaningful error message, I spent several hours trying to figure this one out?
The code above seems to work fine for me (can't reproduce the issue).
Is it possible that there is a mismatch between the System.Threading.Tasks.Task type being returned and the one expected by the runner? This could be caused by an assembly referencing issue. Do you have two different versions of this class present within the application domain? You can try the preload assembly references setting to see if this helps.
Edit: I've just reviewed the code involved here. NCrunch will throw this exception under the following conditions:
1. If the return value from the async test is null
2. If the return value does not have a full type name of "System.Threading.Tasks.Task" and does not inherit from a type with this name.
Maybe you can try hooking a debugger onto the test and examining its return result. I'm not sure why this is different in your environment compared with mine. Do you get this with a small sample project?
The code above seems to work fine for me (can't reproduce the issue).
Is it possible that there is a mismatch between the System.Threading.Tasks.Task type being returned and the one expected by the runner? This could be caused by an assembly referencing issue. Do you have two different versions of this class present within the application domain? You can try the preload assembly references setting to see if this helps.
Edit: I've just reviewed the code involved here. NCrunch will throw this exception under the following conditions:
1. If the return value from the async test is null
2. If the return value does not have a full type name of "System.Threading.Tasks.Task" and does not inherit from a type with this name.
Maybe you can try hooking a debugger onto the test and examining its return result. I'm not sure why this is different in your environment compared with mine. Do you get this with a small sample project?
Never mind, I am a bit dopey and had a TestInitialize method which was async void, whereas all my tests are async Task.
Sorry about the confusion!
Our team has exactly this (most recent) issue - `Expected a return type of 'System.Threading.Tasks.Task' on an async method` using the latest NCrunch, VS 2017 and .NET Core 2.1.
These tests were running without issue previously.
The most basic test that's failing has no initialization and fails on an `await Task.Delay(50)` (we know this is bad practice to include the delay, so we'll leave that discussion for another day!)
[TestMethod]
async public Task CanEnqueue_GivenOperationsOlderThanSlidingWindowAndOverMaximum_ReturnsTrue()
{
// Arrange
MaximumOperationsGate gate = new MaximumOperationsGate(TimeSpan.FromTicks(1), 1);
gate.Enqueue();
await Task.Delay(50);
// Act
bool result = gate.CanEnqueue();
// Assert
result
.Should()
.BeTrue();
}
Here's a link to dummy project with that exact test in it that replicates the issue: https://1drv.ms/u/s!AmaPTHdCBAnDtp5-vBWzqpvterPb7g