Skip to content

.NET 8 has CS9195 warnings for generated code #1014

@JeremyKuhne

Description

@JeremyKuhne

Actual behavior

.NET 8 has changed a number of APIs from ref to in. This causes warnings in CsWin32 generated code. For example:

\winforms2\src\System.Windows.Forms.Primitives\src\Microsoft.Windows.CsWin32\Microsoft.Windows.CsWin32.SourceGenerator\Windows.Win32.RGBQUAD.InlineArrays.g.cs(47,144): warning CS9195: Argument 1 should be passed with the 'in' keyword [\winforms2\src\System.Windows.Forms.Primitives\src\System.Windows.Forms.Primitives.csproj]

Expected behavior

Conditionalized generation to use in when targeting .NET or higher. Something like this (example from System.Drawing):

#if NET8_0_OR_GREATER
    internal unsafe Span<winmdroot.Graphics.Gdi.RGBQUAD> AsSpan() => MemoryMarshal.CreateSpan(in _0, SpanLength);
#else
    internal unsafe Span<winmdroot.Graphics.Gdi.RGBQUAD> AsSpan() => MemoryMarshal.CreateSpan(ref _0, SpanLength);
#endif

Repro steps

Target any daily drop of .NET 8 after 8/3 and include BITMAPINFO (there are a number of others that fail).

Context

  • CsWin32 version: 0.3.18-beta
  • Win32Metadata version (if explicitly set by project): default
  • Target Framework: net8.0 (8.0.0-rc.1.23402.13)
  • LangVersion (if explicitly set by project): latest

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions