Skip to content

Use AssemblyLoadContext to customize native dependency load #50

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

Merged
merged 4 commits into from
May 15, 2018
Merged

Conversation

tmat
Copy link
Member

@tmat tmat commented May 12, 2018

On Windows DllImport doesn't load a native dependency if it has already been loaded explicitly using LoadLibrary. That's not the case on Linux and the loader attempts to load the dependency from next to the referencing assembly.

To address this issue we implement a custom AssemblyLoadContext that handles the loading.

@tmat tmat changed the title Load context WIP: Load context May 12, 2018
@tmat tmat changed the title WIP: Load context Use AssemblyLoadContext to customize native dependency load May 15, 2018
@tmat tmat merged commit 29b3197 into master May 15, 2018
@tmat tmat deleted the NativeLoad branch May 15, 2018 17:05
@jkotas
Copy link
Member

jkotas commented May 15, 2018

cc @jeffschwMSFT This PR is a good example of what one has to do to compensate for the lack of better plugin model. GitLoaderContext has the interesting code.

@tmat
Copy link
Member Author

tmat commented May 15, 2018

@jeffschwMSFT This is also simplified - I hard coded RIDs that the native library currently builds for. Once the library builds for multiple Linux flavors it will get more complicated.

@nguerrera
Copy link
Contributor

@tmat Did the pre-loading work on some Linuxes but not others? I'm actually seeing P/Invoke to already loaded library work on Ubuntu, but I can't explain why based on this and other related issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants