Skip to content

Dll search path sequence changed in dotnet 9 if we use symlink to a exe. #112346

Open
@hmisaki

Description

@hmisaki

Description

I'm working on migrating a Windows project from .NET 8 to .NET 9. During this process, I discovered a change in behavior when launching an executable via a symlink. Specifically, the DLL search sequence differs between .NET 8 and .NET 9 when using a symlink to run the executable.

To illustrate the issue, I created a sample project to reproduce the problem and used the Process Monitor tool to compare the behavior. Below is the result of the comparison between .NET 8 and .NET 9:
Image

This change in behavior could potentially lead to different results in some code execution. For example,

/// Gets the file path of the current module.
std::wstring getModuleFileName()
{
    MEMORY_BASIC_INFORMATION mb;
    VirtualQuery(getModuleFileName, &mb, sizeof(mb));
    HINSTANCE hInst = reinterpret_cast<HINSTANCE>(mb.AllocationBase);
    std::wstring path(MAX_PATH, L'\0');
    DWORD nRet = ::GetModuleFileNameW(hInst, &path[0], MAX_PATH);
    path.resize(nRet);
    return path;
}

Reproduction Steps

Using .NET 8 SDK:

  1. Create a Console App project named "APP".
  2. Create a Class Library project named "LIBA".
  3. Set the APP project to depend on the LIBA project.
  4. Build both the APP and LIBA projects.
  5. Use the mklink command to create symlink files for *.dll, *.exe, and *.runtimeconfig.json in a deployment folder.
  6. Use Process Monitor to track the file search sequence for LIBA.dll.
  7. Double-click the symlinked APP.exe file to launch the executable.

Using .NET 9 SDK:
Follow the same steps as outlined in the .NET 8 SDK section.

Expected behavior

It should search the folder where the symlink file is located, as we are launching the executable from this folder.

Actual behavior

It first searches the folder where the source APP.exe is located.

Regression?

Yes

Known Workarounds

Stop using Symfile and copy the APP.exe to the deployment folder.

Configuration

Dotnet 9.0 in windows

Other information

none

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions