Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

If test contains await, then [AllureStep] failed with System.ArgumentNullException : Value cannot be null. (Parameter 'key') #28

Closed
redfirefox opened this issue Mar 29, 2020 · 7 comments

Comments

@redfirefox
Copy link

This code given exception:
[Test]
public async Task Test()
{
await Task.Delay(1000);
Hello();
}

[AllureStep]
public void Hello()
{
}

System.ArgumentNullException : Value cannot be null. (Parameter 'key')
Stack Trace:
ConcurrentDictionary2.ThrowKeyNullException() ConcurrentDictionary2.TryGetValue(TKey key, TValue& value)
ConcurrentDictionary2.get_Item(TKey key) AllureStorage.Get[T](String uuid) AllureStorage.AddStep(String parentUuid, String uuid, StepResult stepResult) AllureLifecycle.StartStep(String parentUuid, String uuid, StepResult stepResult) AllureLifecycle.StartStep(String uuid, StepResult result) AllureStepAspect.WrapStep(String name, MethodBase methodBase, Object[] arguments, Func2 method)
Tests.__a$_around_Hello_100663386_w_0(Object[] )
Tests.Hello()

But this code - successful:
[Test]
public async Task Test()
{
Task.Delay(1000).GetAwaiter().GetResult();
Hello();
}

@unickq
Copy link
Owner

unickq commented May 7, 2020

I reproduced this issue, debugged through allure.commons.
But can't answer why with await new step we create can't find its parent.
image

@ProAntix
Copy link

ProAntix commented May 7, 2020

I have this issue too. Very perplexing.

@unickq
Copy link
Owner

unickq commented May 8, 2020

@ProAntix @redfirefox
Created issue allure-framework/allure-csharp#106 in base repo

@unickq
Copy link
Owner

unickq commented Jun 25, 2021

Another example - #41 (comment) by @bloodgang94

[AllureNUnit]
    public class AllureAsyncTest
    {
        [Test]
        public async Task Test()
        {
            var testUser = await GenerateAsync();
            AllureLifecycle.Instance.WrapInStep(() =>
            {
                Assert.AreEqual(testUser, "a");
            });
        }

        public static async Task<string> GenerateAsync()
        {
            return await Task.Run(() => Generate());
        }

        public static string Generate()
        {
            Thread.Sleep(1000);
            return "AAA";
        }
    }

System.ArgumentNullException : Value cannot be null. (Parameter 'key')
   at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNullException()
   at System.Collections.Concurrent.ConcurrentDictionary`2.TryGetValue(TKey key, TValue& value)
   at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)

@NaZaRKIN123
Copy link

Any updates here?

@EvgenyMarchuk
Copy link

The same issue and critical for me! Pls, solve the problem! Thanks

@unickq
Copy link
Owner

unickq commented Dec 8, 2022

please follow https://github.com/allure-framework/allure-csharp/tree/main/Allure.NUnit
since all the code there - should be much easier to fix

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants