dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.44k stars 4.76k forks source link

For a network drive, System.Windows.Forms.Application.StartupPath returns a path with \?UNC\ prefix #109846

Open Aniobodo opened 2 weeks ago

Aniobodo commented 2 weeks ago

.NET version

9.0

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

It worked in .NET 8

Issue description

System.Windows.Forms.Application.StartupPath returns a path with \?UNC\ prefix

Steps to reproduce

observe System.Windows.Forms.Application.StartupPath in Visual Studio debug mode.

Image

Zheng-Li01 commented 1 week ago

The issue can reproduce .NET 9.0 & latest .NET 10.0 as below screenshot. Image

JeremyKuhne commented 1 week ago

We just return what the .NET runtime gives us for AppContext.BaseDirectory.

dotnet-policy-service[bot] commented 1 week ago

Tagging subscribers to this area: @vitek-karas, @agocke, @vsadov See info in area-owners.md if you want to be subscribed.

ericstj commented 1 week ago

I repro this, looks to me like AppContext.BaseDirectory is just returning Assembly.GetEntryAssembly()?.Location which also shows this change. Seems that just returns the path that was passed in when loading - so this is either a change to the loader or the host that caused this.

agocke commented 1 week ago

This is a regression likely caused by my change in https://github.com/dotnet/runtime/pull/99576.

In following the path to determine if it is a symbolic link the path was converted to a UNC path.

My suspicion is that this can be fixed by also checking if the target path is a UNC path instead of just an extended path here but I haven't yet convinced myself that's all that's needed.

dotnet-policy-service[bot] commented 1 week ago

Tagging subscribers to this area: @vitek-karas, @agocke, @vsadov See info in area-owners.md if you want to be subscribed.