Skip to content

Buffer.BlockCopy count in elements (CA2018)

Key dotnet.codequality.blockcopy-count · Severity warning · Category codequality

Microsoft analyzer CA2018. Flags Buffer.BlockCopy given an element count where it expects bytes - on anything but a byte array only part of the data is copied.

Buffer.BlockCopy(source, 0, target, 0, source.Length); // int[]
Buffer.BlockCopy(source, 0, target, 0, source.Length * sizeof(int));