dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.11k stars 220 forks source link

MCG0037 error release build with Kernel32 #606

Closed dilaratank closed 2 years ago

dilaratank commented 2 years ago

I have updated PInvoke.BCrypt, PInvoke.Windows.Core, and PInvoke.Kernel32 using the NuGet packages to version 0.7.124 because of a warning I got about deprecated debug information levels.

Debug builds are all successful and I can deploy my app. However, release builds result in the following error:

MCG0037: MCG0037:InvalidCSharpIdentifierName Struct 'PInvoke.Kernel32+ACCESS_MASK' in assembly 'Assembly(Name=PInvoke.Kernel32, Version=0.7.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a)' has a field with name '<Value>k__BackingField' that is invalid. This could be because the name is obfuscated or the field is auto-implemented by the compiler. Please make sure the field name follows C# identifier conventions. ChipSoft.Mobile.Apps.HiX.XF.UWP

How can this be fixed?

AArnott commented 2 years ago

I've never seen an error like this before. I agree this field name looks like it's backing an auto-property. We probably shouldn't be using auto-properties in structs for interop purposes, although in this case it's the only field so it shouldn't cause any functionally incorrect interop. We can fix this by defining the field ourselves. I'm surprised that the MCG tool (whatever that is) has a problem with it.

dilaratank commented 2 years ago

Thanks so much for the quick reply and fix. Do you have any information on when a new version will be released on NuGet? :)

AArnott commented 2 years ago

We just released one a week ago, and we have some active PRs, so probably not in the next several days. But you can read the paragraph in our readme just above the contribution section for a tip on how to consume the packages from our CI if you can't wait for the next release.