-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Set ExactSpelling=true on P/Invokes in System.Private.CoreLib that already specify the unicode W suffix #36257
Conversation
already specify the unicode W suffix
@@ -16,7 +16,7 @@ internal static partial class Advapi32 | |||
{ | |||
// Note: RegCreateKeyEx won't set the last error on failure - it returns | |||
// an error code if it fails. | |||
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegCreateKeyExW")] | |||
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegCreateKeyExW", ExactSpelling = true)] | |||
internal static extern int RegCreateKeyEx( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR, but we might want to subsequently rename all of the methods to use the exact entrypoint name; doing that would make it more clear at the call site exactly which method was being used, would remove the need to specify EntryPoint as well, would increase our consistency (sometimes we use W in the name and sometimes we don't), and also fits with the goal of minimizing magic. Not a big deal, though.
The comment at #35695 (comment) suggests that we're doing this erroneously on Unix as well. Is that the case? |
#33246 for not doing it on Unix is already addressed and we are no longer doing the probing there. |
I even reviewed #33250. Losing my mind apparently :-) |
If a p/invoke is declared with
CharSet.Unicode
andExactSpelling=false
, the runtime will (on Windows) look for both the specified entry point name and the name with theW
suffix. We explicitly specify theW
suffix for the entry point name in a number of cases without settingExactSpelling=true
, resulting in the runtime looking for entry points that we know will not exist (e.g. looking forGetEnvironmentVariableWW
in kernel32).This change updates such cases in
System.Private.CoreLib
to setExactSpelling=true
.cc @AaronRobinsonMSFT @jkoritzinsky @stephentoub