Skip to content

CA1823 incorrectly flags const used as a fixed buffer length #37593

Open
@stephentoub

Description

@stephentoub

Analyzer package

Microsoft.CodeAnalysis.FxCopAnalyzers

Package Version

v2.9.4

Diagnostic ID

CA1823

Repro steps

using System.Runtime.InteropServices;

class Program
{
    static void Main() { }

    private const int SomeLength = 16;

    [StructLayout(LayoutKind.Sequential)]
    internal unsafe struct SomeStruct
    {
        internal fixed byte FixedBuffer[SomeLength];
    }
}

Expected behavior

No warnings.

Actual behavior

The CA1823 analyzer flags the SomeLength const as being unused:

Program.cs(7,23,7,33): warning CA1823: Unused field 'SomeLength'.

even though obviously it is being used.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions