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

Description

Observed while using the new Windows Forms designer to design a migrated app from net461 to net5.0. This doesn’t appear to be a problem while running an app, but it is a problem when the code is executed in the Windows Forms designers (which is now run out of proc).

image

image

at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
at System.Configuration.Internal.ConfigurationManagerInternal.System.Configuration.Internal.IConfigurationManagerInternal.get_ExeProductName()
at System.Configuration.ApplicationSettingsBase.get_Initializer()
at System.Configuration.ApplicationSettingsBase.CreateSetting(PropertyInfo propertyInfo)
at System.Configuration.ApplicationSettingsBase.EnsureInitialized()
at System.Configuration.ApplicationSettingsBase.get_Properties()
at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
at System.Configuration.SettingsBase.get_Item(String propertyName)
at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
at GitCommands.Properties.Settings.get_IsPortable() in D:\Development\gitextensions2\GitCommands\Properties\Settings.Designer.cs:line 31

When I debugged in, for some strange reason AppDomain.CurrentDomain.BaseDirectory was returning \\?\C:\Users\igveliko\AppData\Local\Temp\WinFormsCache\exm5a4ew.gwt\ image

However when try run the same code locally AppDomain.CurrentDomain.BaseDirectory returns path without leading \\?\: image

In essence this, what I think, is happening:

string baseDirectory = @"\\?\C:\Users\igveliko\AppData\Local\Temp\WinFormsCache\exm5a4ew.gwt\";
string manifestModuleName = @"DesignToolsServer.dll";
string configBasePath = Path.Combine(baseDirectory, manifestModuleName);
Uri uri = new Uri(configBasePath);
Console.WriteLine(uri.LocalPath);

image

Repro steps
  1. git clone -v --recurse-submodules --depth 1 --no-single-branch --progress "https://github.com/gitextensions/gitextensions.git" "<path>/gitextensions"
  2. dotnet restore
  3. Open GitExtensions.sln in VS
  4. Ignore Wix warning, trust all repos
  5. Navigate to AppSettings.IsPortable() and remove IsDesignMode
    diff --git a/GitCommands/Settings/AppSettings.cs b/GitCommands/Settings/AppSettings.cs
    
    -        public static bool IsPortable() => !IsDesignMode && Properties.Settings.Default.IsPortable;
    +        public static bool IsPortable() => Properties.Settings.Default.IsPortable;
    
  6. Compile
  7. Open FormAbout in designer image

Configuration

  • .NET 5.0.6
  • .NET: 6.0.0-rc.1.21401.1

Regression?

¯\_(ツ)_/¯ I struggle to tell what is the cause of this strange behaviour

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (15 by maintainers)

Most upvoted comments

After syncing with @JeremyKuhne I believe I was correctly using manifest file and correctly enabled everything. I was able to run the app in cmd.exe from outside of the current directory (so that current directory is relatively short) and then using full path. For System.Diagnostics.Process I don’t think it works with long paths, see the issue I’ve created - I’ve added potential workaround for long paths as well but it will only work if you don’t pass any arguments to the exe: https://github.com/dotnet/runtime/issues/58492

If you use the workaround then after fixing this issue this scenario can be unblocked (assuming you don’t pass any arguments to the app, if you do then last bullet point in #58492 has to be fixed as well)

@krwq This stuff should work. Feel free to ping me on teams regarding long path technical details. 😃