You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When implementing async disposal via pattern, you should be able to use a nullable version of the struct in the await using statement:
Repro:
using System;using System.Threading;using System.Threading.Tasks;namespaceSystem{publicinterfaceIAsyncDisposable{
ValueTask DisposeAsync();}}publicclassC{publicstaticasync Task M(){StructDisposer?a=null;awaitusing(a){}// DisposeAsync is not invokedStructDisposer?b=new StructDisposer();awaitusing(b){}// DisposeAsync is invoked}}publicstructStructDisposer/*: IAsyncDisposable*/{publicasync ValueTask DisposeAsync()=> Console.WriteLine("DisposeAsync");}
Expected Behaviour:
Compiles successfully.
Actual Behavior:
error CS8410: 'StructDisposer?': type used in an async using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method.
Workaround:
Explicitly implement the IAsyncDisposable interface, and the code will compile and run successfully.
[jcouv update:] this issue is reference in the design doc. Should update the design doc when closing this issue.
The text was updated successfully, but these errors were encountered:
When implementing async disposal via pattern, you should be able to use a nullable version of the struct in the
await using
statement:Repro:
Expected Behaviour:
Compiles successfully.
Actual Behavior:
error CS8410: 'StructDisposer?': type used in an async using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method.
Workaround:
Explicitly implement the IAsyncDisposable interface, and the code will compile and run successfully.
[jcouv update:] this issue is reference in the design doc. Should update the design doc when closing this issue.
The text was updated successfully, but these errors were encountered: