Description
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:
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:
- Create a Console App project named "APP".
- Create a Class Library project named "LIBA".
- Set the APP project to depend on the LIBA project.
- Build both the APP and LIBA projects.
- Use the
mklink
command to create symlink files for*.dll
,*.exe
, and*.runtimeconfig.json
in a deployment folder. - Use Process Monitor to track the file search sequence for
LIBA.dll
. - 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
Type
Projects
Status