Issue with DllImport
While exploring how DllImport worked on Linux, I found the following issue at this line: https://github.com/dotnet/coreclr/blob/master/src/vm/dllimport.cpp#L7165
It seems that the code forgot to assign the result of the call to LoadFromNativeDllSearchDirectories to hmod. Is this expected?
@manu-silicon You're right. Thanks for finding this issue!
@adityamandaleeka You are welcome.
Wouldn't it be nice if the language / compiler complained loudly when return values were ignored?
https://twitter.com/xjoeduffyx/status/730991667960893440
:smirk:
@adityamandaleeka I just discovered this as well and I have a fix (https://github.com/dotnet/coreclr/pull/5048) that fixes this as well as a different issue. Our PR probably going to conflict since I'm moving that exact same code.
@yizhang82 I've closed my PR, and am reassigning this issue to you.
@adityamandaleeka Thank you!
Fixed with dotnet/coreclr#5048
@yizhang82 By the way, how one can set NATIVE_DLL_SEARCH_DIRECTORIES?
@manu-silicon Only host can. See https://github.com/dotnet/coreclr/blob/f4fe31a03dca4ede37bd6451d0c81365ee9ee7e4/src/coreclr/hosts/corerun/corerun.cpp
I see. Is there a way to have that set of directories searched too for PInvoke? That would help tremendously!
Yep. It is being searched already and that's exactly what LoadFromNativeDllSearchDirectories does. My other PR dotnet/coreclr#5048 only changes the order.
Actually I found that one could define the CORE_LIBRARIES environment variable but this only seems to work on Windows. The unix version of corerun doesn't check for it. Would be nice to have them consistent.
@manu-silicon That's a host specific issue since host owns translating the environment variables into NATIVE_DLL_SEARCH_DIRECTORIES that is understood by the runtime. @schellap Can you take a look and create a issue as well? /cc @gkhanna79
In the meantime, I'll work on porting the Windows code to unixcoreruncommon to fetch the value of CORE_LIBRARIES as I need this to run some program on Unix. Thanks!
Corelibraries is for internal development. We should probably clean it up and remove it. You should use native ski search path envvar only.
Not sure to understand what native ski means. I just made a patch for picking up from CORE_LIBRARIES. See https://github.com/dotnet/coreclr/compare/master...manu-silicon:core_libraries?expand=1 Let me know if this is worth creating a pull request.
@manu-silicon Sorry, auto-correct on phone does its own thing.
CORE_LIBRARIES is just a development/internal-testing environment variable and should not be relied upon. If you wish to add it to unixcorerun for consistentcy, that is fine. But this is not expected to be formally supported in any host used in formal scenarios. The formal way to specify the folders to look for pinvoke targets is NATIVE_DLL_SEARCH_PATHS.
@gkhanna79 I understand that but how do I set this as a user? I only found CORE_LIBRARIES as a solution.
You cannot - this is a host property and you will need to write a host that sets it. For .NET Core, this is automatically computed based upon the app manifest and .NET Host passes it to the runtime. If you have a scenario where you wish to have an external user specify such a value, consider authoring a host.
I was thinking about an app manifest too. Is this supported just for Windows?