Skip to content

Conversation

@lambdageek
Copy link
Member

If there's a P/Invoke to a library, direct netcore_probe_for_module to look in NATIVE_DLL_SEARCH_DIRECTORIES, followed by the directory containing the managed assembly.

Fixes #59766

If there's a P/Invoke to a library, direct `netcore_probe_for_module` to look
in NATIVE_DLL_SEARCH_DIRECTORIES, followed by the directory containing the
managed assembly.

Fixes dotnet#59766
@ghost
Copy link

ghost commented Sep 30, 2021

Tagging subscribers to this area:
See info in area-owners.md if you want to be subscribed.

Issue Details

If there's a P/Invoke to a library, direct netcore_probe_for_module to look in NATIVE_DLL_SEARCH_DIRECTORIES, followed by the directory containing the managed assembly.

Fixes #59766

Author: lambdageek
Assignees: -
Labels:

area-AssemblyLoader-mono

Milestone: -

@lambdageek
Copy link
Member Author

@jkoritzinsky are there test cases or specific scenarios that we should enable to try this out?

@jkoritzinsky
Copy link
Member

My test case was the DllImportGenerator.Tests suite in #59658. I'll locally test out this change in that branch to validate that the fix works.

@jkoritzinsky
Copy link
Member

I've validated that this fix gets us further to getting those tests to work. I'll file another issue for the next problem I've encountered.

@jkoritzinsky
Copy link
Member

Here's the issue for the next problem I encountered if you're interested: #59815

@vargaz
Copy link
Contributor

vargaz commented Sep 30, 2021

Are native libraries supposed to be in the same dir as managed assemblies ?

@jkoritzinsky
Copy link
Member

By default, having native libraries in the same directory as managed assemblies is supported on CoreCLR and has been for years https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.defaultdllimportsearchpathsattribute?view=net-5.0

As the documentation for DefalutDllImportSearchPathsAttribute states, you can use that attribute to override the default behavior:

Use this attribute to prevent the Win32 LoadLibraryEx function from searching the current working directory.

@lambdageek lambdageek merged commit a2f721e into dotnet:main Sep 30, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
@lambdageek lambdageek deleted the fix-gh-59766 branch March 19, 2022 16:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mono does not load native shared libraries next to an assembly with a DllImport to it.

3 participants