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

Feature Request: A mechanism for unloading and reloading unmanaged libraries while using P/Invoke #12553

Closed
hez2010 opened this issue Apr 22, 2019 · 3 comments

Comments

@hez2010
Copy link
Contributor

hez2010 commented Apr 22, 2019

Currently there's no way to unload unmanaged dynamic libraries while using P/Invoke.

Sometimes we need to hot-upgrade without restarting host process, absolutely that we can use LoadLibrary/FreeLibrary to achieve that but it's really inconvenient, and also we cannot invoke methods in dll directly by calling their method names/ordinals.

So I think it is necessary to provide a mechanism for unloading/reloading dlls while using P/Invoke.

@hez2010 hez2010 changed the title Feature Request: A mechanism for unloading and reloading unmanaged libraries using P/Invoke Feature Request: A mechanism for unloading and reloading unmanaged libraries while using P/Invoke Apr 22, 2019
@RussKeldorph
Copy link
Contributor

@janvorli

@AaronRobinsonMSFT
Copy link
Member

This isn't something we are likely to change via the DllImport approach. There are several reasons, but mostly it will lead to invalid P/Invoke stubs that could result in unsafe execution if the associated native library is unloaded.

absolutely that we can use LoadLibrary/FreeLibrary to achieve that but it's really inconvenient, and also we cannot invoke methods in dll directly by calling their method names/ordinals.

Agreed. The proposed C# function pointer feature along with the NativeLibrary should make much of this less onerous.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@tapika
Copy link

tapika commented Jun 19, 2020

Agreed. The proposed C# function pointer feature along with the NativeLibrary should make much
of this less onerous.

I guess this is one more dynamic approach how to proceed. But would it be possible to introduce some additional function call to release loaded library, which was used with [DllImport] attribute.

Then [DllImport] can be used as such, without need to coding everything dynamically via NativeLibrary.

Btw, one approach is to create customized [DllImport], which would in a turn use NativeLibrary, and provide function for release loaded dll. (Reinvent the wheel)

@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants