Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RCS1229 false positive in unsafe context #1664

@antoinebj

Description

@antoinebj

This code triggers a false positive because async/await is not possible in an unsafe context:

internal sealed unsafe class UnsafeStream(void* unmanagedMemory) : Stream
{
    private readonly void* _unmanagedMemory = unmanagedMemory;

    //                             ↓↓↓ RCS1229: Use async/await when necessary
    public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
    {
        // try is required to trigger it
        try
        {
            var tcs = new TaskCompletionSource<int>();

            // Do stuff with _unmanagedMemory that will run async and use the TCS to complete the returned task

            return new ValueTask<int>(tcs.Task);
        }
        catch
        {
            throw;
        }
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions