-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix native library resolver to handle cases with extension #20912
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
Open
SteveL-MSFT
wants to merge
6
commits into
PowerShell:master
Choose a base branch
from
SteveL-MSFT:native-resolver
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3b5fc2a
Fix native library resolver to handle cases with extension
SteveL-MSFT 19003e8
change code to remove invalid extension first
SteveL-MSFT 4756d45
update tests
SteveL-MSFT 1adc65c
address codefactor
SteveL-MSFT 99172aa
Update src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadCon…
SteveL-MSFT 5d04af6
Update src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadCon…
SteveL-MSFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
This could be controversial. Is it worth changing the extension that is specified by the developer in his code?
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.
Please look #20740 (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.
Isn't this the problem with the sqlite repro? It seems that the developer accidentally specified .dll but also shipped libraries for other OS.
Uh oh!
There was an error while loading. Please reload this page.
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.
There is no requirement that a shared library does end with dylib, dll or so. merely convention. If you remember on Windows control panel extensions, drivers and OLE controls were dlls but did not have dll as the extension.
I don't think the developer accidentally specified .dll in the DllImport, the examples from Microsoft have "user32.dll" etc in them. As the module is common and only the shared libraries are different, it is consistent to have them all with the same name but just in a different directory according to architecture.
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.
DllImport documentation says that we can use
You can provide a full or relative path.orAs a minimum requirement, you must supply the name of the DLL containing the entry point.and says nothing about extensions. So developers are free to use any file extension for dynamic library.While I agree that deviating from the usual values looks amazing, there are no standards to call it a bug, especially since these non-standard extensions work in C# applications. If we forcibly change the extension, then obviously these applications will stop working.
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.
Perhaps if it has an extension, we try loading it as-is, and if it fails, then try the os specific extension?
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.
I suggest not removing anything from the string that was originally given, trust that the original string was correct, because if it is in published code it must have been tested like that and worked.
The simplest would be...
try the exact given name
if that does not work try with operating system specific extension appended
No replacing of the extension with something else, only appending.
So if you don't specify an extension you will get the OS one.
If you do, your extension will be honoured first, then it will try with your full name plus OS extension.
And of course it has to go through (a) in the root directory (b) in the directory with just the CPU name (c) in the directory with OS-CPU
So may take 6 attempts to load the DLL.
Uh oh!
There was an error while loading. Please reload this page.
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.
The fallback doesn't make a lot of sense. If a developer specified
DllImport("interop.msft")in the code, then obviously he is referring to the realinterop.msftfile on file system and there is nointerop.msft.dllfile orinterop.dllfile.(And I don't think DllImport is smart enough to handle multi-dot names. I mean
DllImport("interop.msft")will do not searchinterop.msft.dllon Windows andinterop.msft.soon Linux. If he does, it will work for us automatically.)