C# - .NET 5+에서 warning CA1416: This call site is reachable on all platforms. '...' is only supported on: 'windows' 경고 발생
.NET 6에서 Windows Forms 프로젝트를 생성 후 다음과 같은 식으로 코딩을 하면,
// C# - OpenCvSharp.VideoWriter에 BMP 파일을 1초씩 출력하는 예제
// ; https://www.sysnet.pe.kr/2/0/12485
private static byte[] GetBitmapData(Bitmap frameBitmap)
{
var bitmapData = frameBitmap.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, frameBitmap.Size),
ImageLockMode.ReadOnly,
PixelFormat.Format24bppRgb);
try
{
var length = bitmapData.Stride * bitmapData.Height;
var data = new byte[length];
Marshal.Copy(bitmapData.Scan0, data, 0, length);
return data;
}
finally
{
frameBitmap.UnlockBits(bitmapData);
}
}
빌드 시 아래와 같은 경고가 뜹니다.
1>C:\temp\WindowsFormsApp1\test.cs(91,30,91,47): warning CA1416: This call site is reachable on all platforms. 'BitmapData.Stride' is only supported on: 'windows'.
CA1416 경고에 대해서는 다음의 문서에서 잘 설명하고 있으니,
CA1416: Validate platform compatibility
; https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1416
자신의 상황에 맞게 적절한 조치를 취하시면 됩니다. 가령 제 경우에는, 위의 프로그램을 윈도우에서만 실행할 것이므로 AssemblyInfo.cs 파일에 다음의 특성을 정의해 해결했습니다.
using System.Runtime.Versioning;
[assembly: SupportedOSPlatform("windows")]
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]