`using` - declaration does not work with DisposableVariableNotDisposedAnalyzer · Issue #1043 · code-cracker/code-cracker · GitHub
Skip to content

using - declaration does not work with DisposableVariableNotDisposedAnalyzer #1043

Description

@pgrm

The following code:

public async Task DoStuffAsync()
{
    // ... some code ...

    using var buffer = new MemoryStream();
    await File.WriteToStreamAsync(buffer);

    UseBuffer(buffer.ToArray());
}

Throws the following exception when building:

Analyzer 'CodeCracker.CSharp.Usage.DisposableVariableNotDisposedAnalyzer' threw an exception of type 'System.ArgumentNullException' with message 'Value cannot be null. (Parameter 'syntax')'.

Changing it to the old syntax works fine:

public async Task DoStuffAsync()
{
    // ... some code ...

    using (var buffer = new MemoryStream())
    {
        await File.WriteToStreamAsync(buffer);
        UseBuffer(buffer.ToArray());
    }
}

However, this doesn't break always. I do have other cases in the same project, where the new syntax works and again some, where it doesn't work. So it's hard to create a generic replication project, but for those methods where it doesn't work, it fails every single time, I try to compile it with the new syntax and works every single time, I try to compile it with the old syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions