-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add native dll resolver #11032
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
Add native dll resolver #11032
Conversation
|
This looks super promising, wow! Nice work! 😍 I have one suggestion just for compatibility; prior to 6.2 (or 6.1? Don't recall exactly) pwsh was able to search the location the library was in for native DLLs (though not subfolders). As part of one of the changes in 6.2, that was removed, and this seems like a sensible place to add it. Can we have it also check the same folder as the managed library so that anything that was using the old behaviour works again as well? |
Yes, we can. I think first we need to have a standard (RFC?) how we search, order is important. Also we should consider security compliance. |
|
@iSazonov we may want to look into whether there's a way to pull the acceptable RIDs from |
|
@vexx32 .Net Core has not API to expose RIDs.
|
|
@iSazonov yeah I wondered. The reason I ask is that some RIDs include OS version as well as architecture, so we might be missing (for example) a folder with |
|
It makes sense to follow the .NET RID hierarchy so that it's consistent and predictable. It doesn't have to be an exact match, but I can image build scripts that create the native folder under the RID passed to msbuild. So for macOS, you're just as likely to see |
|
Will replace "osx" with "osx-x64". |
It is just a case I name as "edge". Very unlikely to be needed. I believe any developer prefer to create portable solutions. |
|
🤔 along with this, would it perhaps be feasible to expose a public API to allow module authors to add specific paths to search when working in those edge cases? (maybe that's a future discussion 😆) |
The API is already in .Net Core. See DllImportResolver callbacks reference above. I guess it is possible to use even script delegate for the callback. |
src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
Outdated
Show resolved
Hide resolved
daxian-dbw
left a comment
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.
Can you please add one test?
I guess you can fake a native library file (renaming a text file to native.dll), then the resolution should succeed but loading the native library will fail with a BadImageFormatException -- An attempt was made to load a program with an incorrect format. (0x8007000B).
src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs
Outdated
Show resolved
Hide resolved
…text.cs Co-Authored-By: Dongbo Wang <dongbow@microsoft.com>
|
@iSazonov Please don't use 7.0-consider for PRs... I'll try to update the descriptions to say which milestones are for issues and which are for PRs. |
daxian-dbw
left a comment
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.
LGTM
|
Added a reference to new doc issue. |
|
🎉 Handy links: |
PR Summary
Resolve #9488
Add a native dll resolver to discover and load native dlls based on OS platform and architecture.
PR Context
Releated #3091
If a managed dll has native dependencies the handler will try to find these native dlls.
1. Gets the managed.dll location (folder)
2. Based on OS name and architecture name builds subfolder name where it is expected the native dll resides:
3. Loads the native dll
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.