Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Aniobodo opened this issue Nov 13, 2024 · 8 comments
Assignees
Milestone

Comments

@Aniobodo
Copy link

.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

@Aniobodo Aniobodo added the untriaged New issue has not been triaged by the area owner label Nov 13, 2024
@Zheng-Li01
Copy link
Member

Zheng-Li01 commented Nov 14, 2024

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

@JeremyKuhne
Copy link
Member

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

@JeremyKuhne JeremyKuhne transferred this issue from dotnet/winforms Nov 14, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 14, 2024
@ericstj ericstj removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 17, 2024
Copy link
Contributor

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

@ericstj
Copy link
Member

ericstj commented Nov 17, 2024

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 agocke added this to the 9.0.x milestone Nov 18, 2024
@agocke agocke self-assigned this Nov 18, 2024
@agocke agocke removed the untriaged New issue has not been triaged by the area owner label Nov 18, 2024
@agocke
Copy link
Member

agocke commented Nov 19, 2024

This is a regression likely caused by my change in #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.

Copy link
Contributor

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

@Aniobodo
Copy link
Author

Aniobodo commented Dec 3, 2024

Fixed?

@bitapparat
Copy link

bitapparat commented Dec 12, 2024

I just wanted to add that this issue also prevents any WPF app with a MediaElement from running from a UNC path. While resolving the Uri of the MediaElement.Source WPF passes the result of AppDomain.BaseDirectory to the Uri constructor, resulting in a UriFormatException because the Uri constructor can't deal with the \\?UNC\ prefix.

This happens here:
https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SecurityHelper.cs#L72
appBase = new Uri(domain.BaseDirectory);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

6 participants