Skip to content

Conversation

@krwq
Copy link
Member

@krwq krwq commented Sep 3, 2021

Fixes: #56897

Currently WinForms designer launches the process such that it prepends \\?\ because temporary directory it uses might end up with long path issues. This fixes the issue.

I did not find any scenarios where using Uri would have any benefits and Path.Combine seem to be fine to use.

Tested by creating a sample app which starts itself and prepends \\?\ to its own path and then executing ConfigurationManager.AppSettings.Get("foo") - in the success path it should return null, currently it throws an exception (only when process is launched with \\?\ prepended). Additionally tested the same when added App.config file with foo setting and made sure it read the value correctly.

Also tested by checking if Path.Combine correctly works for various paths (UNC, regular file path, \\?\ prepended path).

@krwq krwq requested review from eerhardt and jkotas September 3, 2021 13:08
@ghost
Copy link

ghost commented Sep 3, 2021

Tagging subscribers to this area: @safern
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes: #56897

Currently WinForms designed launches the process such that it prepends \\?\ because temporary directory it uses might end up with long path issues. This fixes the issue.

I did not find any scenarios where using Uri would have any benefits and Path.Combine seem to be fine to use.

Tested by creating a sample app which starts itself and prepends \\?\ to its own path and then executing ConfigurationManager.AppSettings.Get("foo") - in the success path it should return null, currently it throws an exception (only when process is launched with \\?\ prepended.

Also tested by checking if Path.Combine correctly works for various paths (UNC, regular file path, \\?\ prepended path).

Author: krwq
Assignees: -
Labels:

area-System.Configuration

Milestone: -

@eerhardt
Copy link
Member

eerhardt commented Sep 3, 2021

Here's the original commit that added the call to new Uri: dotnet/corefx@3f0fff2. Originally (in .NET Framework) we were stripping the file:/// and file:// prefixes from the path. Do we still need to do that? I believe that's what the intention of the new Uri(...).LocalPath was doing. Or are we guaranteed that AppDomain.CurrentDomain.BaseDirectory will never have file:// prefixes?

Also, side question: is new Uri(...) supposed to be able to handle \\?? Would that be a "more complete" fix?

@jkotas
Copy link
Member

jkotas commented Sep 3, 2021

Originally (in .NET Framework) we were stripping the file:/// and file:// prefixes from the path. Do we still need to do that?

It was necessary in .NET Framework because the code started with Assembly.CodeBase. Assembly.CodeBase is url (it can even be http://... in .NET Framework).

Or are we guaranteed that AppDomain.CurrentDomain.BaseDirectory will never have file:// prefixes?

Yes. BaseDirectory is always file path, no file:// prefix.

Also, side question: is new Uri(...) supposed to be able to handle \?? Would that be a "more complete" fix?

Maybe. Uri parsing is very complex with many legacy quirks and any fixes in it are risky and involved. Not a good candidate for .NET 6 fix.

Also, we may want to strip \\? from the BaseDirectory. I believe that our general approach is to avoid leaking \\? to user code where possible.

It may be a good idea to create a follow up issues for both of these.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given @jkotas's answers above, this LGTM.

It may be a good idea to create a follow up issues for both of these.

+1

@krwq
Copy link
Member Author

krwq commented Sep 6, 2021

Thanks @jkotas and @eerhardt!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

Reading configuration settings fails with System.UriFormatException: 'Invalid URI: The hostname could not be parsed.'

3 participants