wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

Remove CA1060 - Move P/Invokes to `NativeMethods` class

Open pomianowski opened this issue 11 months ago • 2 comments

Describe the bug

Native invocations should be moved to different class https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1060

To Reproduce

Open the Wpf.Ui.sln Select the Build...Clean Solution menu item Press Ctrl+F5 to build the solution and run it, without connecting the debugger. F5 to build and connect the debugger. Observe the warnings listed above

Expected behavior

No warnings are generated when building.

Screenshots

No response

OS version

11 2610

.NET version

9.0.200-preview.0.25057.12

WPF-UI NuGet version

4.0.0

Additional context

No response

pomianowski avatar Feb 04 '25 21:02 pomianowski

Some or many of these interop methods are not even used. Also, some duplicate system-provided interop, such as all three of the ones defined in Kernel32: Kernel32.GetLastError -> System.Runtime.InteropServices.Marshal.GetLastSystemError Kernel32.SetLastError -> System.Runtime.InteropServices.Marshal.SetLastSystemError IsDebuggerPresent -> System.Diagnostics.Debugger.IsAttached and/or System.Diagnostics.Debugger.IsLogging Also, the latter 2 have no references, and the former most has only 3 references, all from within comments of User32

I get that perhaps this is meant as just a "placeholder" class for possible future interop methods.

JohnTasler avatar Feb 04 '25 22:02 JohnTasler

Consider migrating to https://github.com/microsoft/CsWin32 so you don’t have to write the native method headers yourself at all.

chucker avatar Feb 06 '25 08:02 chucker