Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException caused by ConfigureAwait.Fody #537

Open
Storm-BE opened this issue May 11, 2023 · 0 comments
Open

NullReferenceException caused by ConfigureAwait.Fody #537

Storm-BE opened this issue May 11, 2023 · 0 comments

Comments

@Storm-BE
Copy link

Storm-BE commented May 11, 2023

Describe the issue

The following code throws a NullReferenceException when processed by ConfigureAwait.Fody.
It finishes successfully when the weaver is disabled.

Console.WriteLine("Hello, World!");
string? someString = null;
await (someString == "anyValue" ? SomeMethodAsync() : SomeMethodAsync());
Console.WriteLine("Finished successfully!");

static Task SomeMethodAsync()
{
    return Task.CompletedTask;
}

It does not throw when I save the Task to a local variable and await in a separate statement

var toAwait = (someString == "anyValue" ? SomeMethodAsync() : SomeMethodAsync());
await toAwait;

Typical stack trace:

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Threading.Tasks.Task.AddTaskContinuationComplex(Object tc, Boolean addBeforeOthers)
   at System.Threading.Tasks.Task.AddTaskContinuation(Object tc, Boolean addBeforeOthers)
   at System.Threading.Tasks.Task.UnsafeSetContinuationForAwait(IAsyncStateMachineBox stateMachineBox, Boolean continueOnCapturedContext)
   at System.Runtime.CompilerServices.TaskAwaiter.UnsafeOnCompletedInternal(Task task, IAsyncStateMachineBox stateMachineBox, Boolean continueOnCapturedContext)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AwaitUnsafeOnCompleted[TAwaiter](TAwaiter& awaiter, IAsyncStateMachineBox box)
   at Program.<Main>$(String[] args) in C:\Repos\experiments\configureawait-fody-nre-bug-repro\Program.cs:line 3
   at Program.<Main>(String[] args)

I'm running:

  • dotnet 6
  • Fody 6.7.0
  • ConfigureAwait.Fody 3.3.2

Minimal Repro

Can be found here: https://github.com/Storm-BE/configureawait-fody-nre-bug-repro

Make an effort to fix the bug

If I find some time I hope to have a look at this myself

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

No branches or pull requests

1 participant