Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 8 has CS9195 warnings for generated code #1014

Closed
JeremyKuhne opened this issue Aug 3, 2023 · 4 comments · Fixed by #1039
Closed

.NET 8 has CS9195 warnings for generated code #1014

JeremyKuhne opened this issue Aug 3, 2023 · 4 comments · Fixed by #1039
Assignees
Labels
bug Something isn't working

Comments

@JeremyKuhne
Copy link
Member

JeremyKuhne commented Aug 3, 2023

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
@JeremyKuhne JeremyKuhne added the bug Something isn't working label Aug 3, 2023
JeremyKuhne added a commit to JeremyKuhne/winforms that referenced this issue Aug 3, 2023
A number of Libarary APIs have had their parameters changed from `ref` to `in` (or `readonly ref`).

This change modifies code that we control and disables the "passing ref to in" warning for the interop assembly until we can get microsoft/CsWin32#1014 resolved.

This change requires a more current Roslyn build and as such I've updated it. Note that VS Intellisense does not support this new feature yet. You can filter out intellisense errors by selecting "Build Only" in the error pane in the meantime (this will not remove red squiggles unfortunately).
@JeremyKuhne JeremyKuhne changed the title .NET 8 has CS9195 errors for generated code .NET 8 has CS9195 warnings for generated code Aug 3, 2023
JeremyKuhne added a commit to dotnet/winforms that referenced this issue Aug 3, 2023
A number of Libarary APIs have had their parameters changed from `ref` to `in` (or `readonly ref`).

This change modifies code that we control and disables the "passing ref to in" warning for the interop assembly until we can get microsoft/CsWin32#1014 resolved.

This change requires a more current Roslyn build and as such I've updated it. Note that VS Intellisense does not support this new feature yet. You can filter out intellisense errors by selecting "Build Only" in the error pane in the meantime (this will not remove red squiggles unfortunately).
JeremyKuhne added a commit to dotnet/winforms that referenced this issue Aug 3, 2023
* Update dependencies from https://github.com/dotnet/runtime build 20230802.13

Microsoft.Internal.Runtime.WindowsDesktop.Transport , Microsoft.NET.Sdk.IL , Microsoft.NETCore.App.Ref , Microsoft.NETCore.App.Runtime.win-x64 , Microsoft.NETCore.ILAsm , Microsoft.NETCore.ILDAsm , Microsoft.NETCore.Platforms , Microsoft.Win32.Registry.AccessControl , Microsoft.Win32.SystemEvents , runtime.win-x64.Microsoft.NETCore.ILAsm , runtime.win-x86.Microsoft.NETCore.ILAsm , System.CodeDom , System.ComponentModel.Composition , System.ComponentModel.Composition.Registration , System.Configuration.ConfigurationManager , System.Data.Odbc , System.Data.OleDb , System.Diagnostics.EventLog , System.Diagnostics.PerformanceCounter , System.DirectoryServices , System.DirectoryServices.AccountManagement , System.DirectoryServices.Protocols , System.IO.Packaging , System.IO.Ports , System.Management , System.Reflection.Context , System.Reflection.MetadataLoadContext , System.Resources.Extensions , System.Runtime.Caching , System.Security.Cryptography.Pkcs , System.Security.Cryptography.ProtectedData , System.Security.Cryptography.Xml , System.Security.Permissions , System.ServiceModel.Syndication , System.ServiceProcess.ServiceController , System.Speech , System.Text.Encoding.CodePages , System.Text.Encodings.Web , System.Text.Json , System.Threading.AccessControl , System.Windows.Extensions , VS.Redist.Common.NetCore.SharedFramework.x64.8.0
 From Version 8.0.0-rc.1.23401.22 -> To Version 8.0.0-rc.1.23402.13

* Handle `ref` to `in` change (#9654)

A number of Libarary APIs have had their parameters changed from `ref` to `in` (or `readonly ref`).

This change modifies code that we control and disables the "passing ref to in" warning for the interop assembly until we can get microsoft/CsWin32#1014 resolved.

This change requires a more current Roslyn build and as such I've updated it. Note that VS Intellisense does not support this new feature yet. You can filter out intellisense errors by selecting "Build Only" in the error pane in the meantime (this will not remove red squiggles unfortunately).

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Jeremy Kuhne <jkuhne@microsoft.com>
dreddy-work pushed a commit to dotnet/winforms that referenced this issue Aug 4, 2023
* [main] Update dependencies from dotnet/runtime (#9648)

* Update dependencies from https://github.com/dotnet/runtime build 20230802.13

Microsoft.Internal.Runtime.WindowsDesktop.Transport , Microsoft.NET.Sdk.IL , Microsoft.NETCore.App.Ref , Microsoft.NETCore.App.Runtime.win-x64 , Microsoft.NETCore.ILAsm , Microsoft.NETCore.ILDAsm , Microsoft.NETCore.Platforms , Microsoft.Win32.Registry.AccessControl , Microsoft.Win32.SystemEvents , runtime.win-x64.Microsoft.NETCore.ILAsm , runtime.win-x86.Microsoft.NETCore.ILAsm , System.CodeDom , System.ComponentModel.Composition , System.ComponentModel.Composition.Registration , System.Configuration.ConfigurationManager , System.Data.Odbc , System.Data.OleDb , System.Diagnostics.EventLog , System.Diagnostics.PerformanceCounter , System.DirectoryServices , System.DirectoryServices.AccountManagement , System.DirectoryServices.Protocols , System.IO.Packaging , System.IO.Ports , System.Management , System.Reflection.Context , System.Reflection.MetadataLoadContext , System.Resources.Extensions , System.Runtime.Caching , System.Security.Cryptography.Pkcs , System.Security.Cryptography.ProtectedData , System.Security.Cryptography.Xml , System.Security.Permissions , System.ServiceModel.Syndication , System.ServiceProcess.ServiceController , System.Speech , System.Text.Encoding.CodePages , System.Text.Encodings.Web , System.Text.Json , System.Threading.AccessControl , System.Windows.Extensions , VS.Redist.Common.NetCore.SharedFramework.x64.8.0
 From Version 8.0.0-rc.1.23401.22 -> To Version 8.0.0-rc.1.23402.13

* Handle `ref` to `in` change (#9654)

A number of Libarary APIs have had their parameters changed from `ref` to `in` (or `readonly ref`).

This change modifies code that we control and disables the "passing ref to in" warning for the interop assembly until we can get microsoft/CsWin32#1014 resolved.

This change requires a more current Roslyn build and as such I've updated it. Note that VS Intellisense does not support this new feature yet. You can filter out intellisense errors by selecting "Build Only" in the error pane in the meantime (this will not remove red squiggles unfortunately).

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Jeremy Kuhne <jkuhne@microsoft.com>

* [main] Update dependencies from dotnet/arcade (#9661)

[main] Update dependencies from dotnet/arcade

* [main] Update dependencies from dotnet/runtime (#9662)

[main] Update dependencies from dotnet/runtime

* Enable nullability in DockEditor, ContentAlignmentEditor and SelectionPanelBase (#9649)

* annotate SelectionPanelBase

* annotate DockEditor

* annotate ContentAlignmentEditor

---------

Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Jeremy Kuhne <jkuhne@microsoft.com>
Co-authored-by: halgab <24685886+halgab@users.noreply.github.com>
@AArnott AArnott self-assigned this Aug 10, 2023
@AArnott
Copy link
Member

AArnott commented Aug 10, 2023

@JeremyKuhne Your repro steps appear to be to generate RGBQUAD, but that is merely a struct that defines no methods at all. Can you give me a better API to generate to emit the warning?

@AArnott
Copy link
Member

AArnott commented Aug 10, 2023

FWIW, I can't find anything in CsWin32 that would ever generate Marshal.QueryInterface method calls.

@JeremyKuhne
Copy link
Member Author

BITMAPINFO generates this particular RGBQUAD inline array wrapper.

@AArnott AArnott assigned AArnott and unassigned JeremyKuhne Sep 15, 2023
@AArnott
Copy link
Member

AArnott commented Sep 15, 2023

I'm able to repro this in a unit test now. Woot.

AArnott added a commit that referenced this issue Sep 18, 2023
AArnott added a commit that referenced this issue Sep 18, 2023
WIP: this doesn't show that the fix works yet because 4.8.0-1.final isn't new enough of a compiler for what the new syntax requires.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants