-
Notifications
You must be signed in to change notification settings - Fork 94
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
GetModuleHandle shouldn't return FreeLibrarySafeHandle #644
Comments
Great feedback, thank you. Moving to the metadata repo so we can fix it at the right place for all projections. |
@mikebattista This issue also affects winforms. |
What is the specific change in the metadata? It currently returns an |
For CsWin32, I guess if the meta data flagged
@AArnott knows better than myself. |
I feel like this has come up before, and if so we may already have a way to express the simple case in metadata. I think For |
Do we use
I will leave it as is. |
They both have |
Assigning to @AArnott to resolve whether this is a metadata issue or C#/Win32 issue. It would seem that |
We need something like this, maybe in internal const string DoNotReleaseAttribute = "DoNotReleaseAttribute";
bool doNotRelease = false;
foreach (CustomAttributeHandle attHandle in this.GetReturnTypeCustomAttributes(methodDefinition) ?? Enumerable.Empty<CustomAttributeHandle>())
{
CustomAttribute att = this.Reader.GetCustomAttribute(attHandle);
if (this.IsAttribute(att, InteropDecorationNamespace, DoNotReleaseAttribute))
{
doNotRelease = true;
break;
}
} |
Wanna take this, @elachlan? We might have a helper method that does the loop-search for you. |
I did implement it and it worked. But not exactly how I'd hoped. Since there was still a friendly overloads, when it probably shouldn't be generated at all. Also if we implement IDisposable on the structs(#596), then we are pushing the problem down the line. I am not sure how to fix that. Maybe wrap the return type? |
The friendly overload should still return a |
ahhhh, thanks. I should be able to get it sorted in the next few days in my free time. |
Actual behavior
GetModuleHandle
returnsFreeLibrarySafeHandle
. Which will callFreeLibrary
on cleanup. But, according to the documentation, this is not necessary to avoid errors:GetModuleHandleEx
partly also affected by this problem, because the cleanup behavior depends on the arguments passedhttps://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulehandleexw#parameters
Expected behavior
A clear and concise description of what you expected to happen.
Repro steps
NativeMethods.txt
content:NativeMethods.json
content (if present):Context
0.1.635-beta
]netstandard2.0
]LangVersion
(if explicitly set by project): [e.g.9
]The text was updated successfully, but these errors were encountered: