Skip to content

Use AssemblyLoadContext to customize native dependency load - #50

Merged
tmat merged 4 commits into
masterfrom
NativeLoad
May 15, 2018
Merged

Use AssemblyLoadContext to customize native dependency load#50
tmat merged 4 commits into
masterfrom
NativeLoad

Conversation

@tmat

@tmat tmat commented May 12, 2018

Copy link
Copy Markdown
Member

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

jkotas commented May 15, 2018

Copy link
Copy Markdown
Member

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

tmat commented May 15, 2018

Copy link
Copy Markdown
Member Author

@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
Copy Markdown
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