Skip to content

Reading application settings in NET WinForms OOP designer fails with exception 'Invalid URI: The hostname could not be parsed" #70318

Description

@tracktownsoftware

Environment

Version 17.2.2

.NET version

net6.0-windows

Did this work in a previous version of Visual Studio and/or previous .NET release?

No, this is new in VS2022 and the NET WinForms OOP designer.

Issue description

This is an issue in the new NET WinForms designer when using the microsoft.winforms.designer.sdk to add design-time support to a custom NET6 WinForms control. Reading application settings at design-time fails with exception “Invalid URI: this hostname could not be parsed”.

I also reported this as feedback from VS2022:
https://developercommunity.visualstudio.com/t/Reading-application-settings-fails-in-th/10055004

Steps to reproduce

My github sample to reproduce:
https://github.com/tracktownsoftware/MicrosoftWinFormsDesignerSDK_AppSettingsBug

The above repository includes a Nuget package you can use to test and reproduce. The nuget package contains a custom NET6 WinForms "MyButton" control with WinForms Designer Extensibility SDK design-time support.

Diagnostics

No response

Activity

  1. RussKie commented on May 30, 2022

    @RussKie
    Contributor

    The application settings are resolved in the context of the currently running app - which in the case of the out-of-proc designer is DesignToolsServer.dll.

    Here's what's going on here. When we're trying to resolve Properties.Settings.HelloWorld, the .NET runtime is trying to locate the DesignToolsServer's settings and it fails here:

    System.Private.Uri.dll!System.Uri.Uri(string uriString)
    System.Configuration.ConfigurationManager.dll!System.Configuration.ClientConfigPaths.ClientConfigPaths(string exePath = null, bool includeUserConfig) Line 77
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ClientConfigPaths.cs(77)
    System.Configuration.ConfigurationManager.dll!System.Configuration.ClientConfigPaths.GetPaths(string exePath, bool includeUserConfig = true) Line 212
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ClientConfigPaths.cs(212)
    System.Configuration.ConfigurationManager.dll!System.Configuration.Internal.ConfigurationManagerInternal.System.Configuration.Internal.IConfigurationManagerInternal.ExeProductName.get() Line 19
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/Internal/ConfigurationManagerInternal.cs(19)
    System.Configuration.ConfigurationManager.dll!System.Configuration.ApplicationSettingsBase.Initializer.get() Line 678
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ApplicationSettingsBase.cs(678)
    System.Configuration.ConfigurationManager.dll!System.Configuration.ApplicationSettingsBase.CreateSetting(System.Reflection.PropertyInfo propertyInfo = {System.Reflection.RuntimePropertyInfo}) Line 459
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ApplicationSettingsBase.cs(459)
    System.Configuration.ConfigurationManager.dll!System.Configuration.ApplicationSettingsBase.EnsureInitialized() Line 584
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ApplicationSettingsBase.cs(584)
    System.Configuration.ConfigurationManager.dll!System.Configuration.ApplicationSettingsBase.Properties.get() Line 140
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ApplicationSettingsBase.cs(140)
    System.Configuration.ConfigurationManager.dll!System.Configuration.SettingsBase.GetPropertyValueByName(string propertyName = "HelloWorld") Line 55
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SettingsBase.cs(55)
    System.Configuration.ConfigurationManager.dll!System.Configuration.SettingsBase.this[string].get(string propertyName) Line 29
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SettingsBase.cs(29)
    System.Configuration.ConfigurationManager.dll!System.Configuration.ApplicationSettingsBase.GetPropertyValue(string propertyName = "HelloWorld") Line 731
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ApplicationSettingsBase.cs(731)
    System.Configuration.ConfigurationManager.dll!System.Configuration.ApplicationSettingsBase.this[string].get(string propertyName) Line 403
    	at /_/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ApplicationSettingsBase.cs(403)
    MyButtonLibrary.dll!MyButtonLibrary.Properties.Settings.HelloWorld.get()
    MyButtonLibrary.dll!MyButtonLibrary.MyButton.ApplicationSettingsTest()
    MyButtonLibrary.Design.dll!MyButtonLibrary.Design.MyButtonActionList.ApplicationSettingsBug()
    

    The issue here is that the designer is located at a path similar to \\?\C:\Users\user\AppData\Local\Microsoft\VisualStudio\17.0_dfbd86c6Exp\WinFormsDesigner\figs3bhx.mvu\ and Uri is unable to handle \\? paths. This was fixed in #56897 for .NET 7, however, it doesn't appear the change was complete as .NET 7 still fails with the same error, though at a different point:
    image
    /cc: @krwq @jeffhandley

  2. MelonWang1 commented on May 30, 2022

    @MelonWang1

    Repro Steps:
    1. Create a Winforms .NET Core 6.0 application
    2. Download and copy "MyButtonLibrary.1.0.102.nupkg" from "\Pack\packages\MyButtonLibrary.1.0.102.nupkg" to "C:\Program Files (x86)\Microsoft SDKs\NuGetPackages"
    3. Right click the project and select " Manguage NuGet Packages…"
    4. The Package source select All and switch Installed to Browse
    5. Search and install "MyButtonLibrary"
    6. Switch to Form designer, drag and drop MyButton control onto Form1
    7. Right click control and select "Change button text using application setting - This FAILS"

    Actual Result:
    The exception pops up.
    error
    seeting

    Expected Result:
    No exception pops up.

  3. tracktownsoftware commented on Jun 1, 2022

    @tracktownsoftware
    Author

    Do you have an ETA when this might be fixed? This issue has blocked us from adding design-time support for our NET6 WinForms control. We can't release until this is fixed.
    Thanks.

  4. transferred this issue fromdotnet/winformson Jun 7, 2022
  5. RussKie commented on Jun 7, 2022

    @RussKie
    Contributor

    @jeffhandley @krwq putting this on your radar.

  6. buyaa-n commented on Jun 14, 2022

    @buyaa-n
    Contributor

    Thanks for the clear repro @tracktownsoftware and the additional details @RussKie as you pointed out the issue caused by the AppDomain.CurrentDomain.BaseDirectory path prefixed with \\?\ when creating Uri at:

    Uri codeBase = new Uri(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assembly.ManifestModule.Name));

    I could be able to fix this by removing the prefix if exist or something like that, but it seems better to be fixed at the Uri constructor or AppDomain.CurrentDomain.BaseDirectory level as @jkotas suggested in previous PR so that we will not see similar issues again. One of the issues even closed, so I would suggest you to go to those issues and ask for urgent fix

  7. removed
    untriagedNew issue has not been triaged by the area owner
    on Jun 14, 2022
  8. added this to the 7.0.0 milestone on Jun 14, 2022
  9. RussKie commented on Jun 21, 2022

    @RussKie
    Contributor

    @karelz this is a core scenario for the Windows Forms designer

  10. 16 remaining items

  11. RussKie commented on Jun 30, 2022

    @RussKie
    Contributor

    Could you give me a hand and point me a release that I can test? I've downloaded the latest nightly (7.0.100-preview.7.22329.1) from dotnet/installer, and it only contains the runtime build from 15 June (7.0.0-preview.6.22314.11+eeb0c1551b5fc9ccd6ceeaf5d2b1504afab249d7), and the fix was merged on 23 June.
    Thank you

  12. RussKie commented on Jun 30, 2022

    @RussKie
    Contributor

    I am afraid this won't work. The daily build contains only Microsoft.NETCore.App workload, and the fix went into System.Configuration.ConfigurationManager.dll, which is a part of Microsoft.WindowsDesktop.App workload.

  13. jkotas commented on Jun 30, 2022

    @jkotas
    Member

    You should be able to get daily build of the System.Configuration.ConfigurationManager.dll package using the instructions at the top of the document.

  14. buyaa-n commented on Jun 30, 2022

    @buyaa-n
    Contributor

    Could you give me a hand and point me a release that I can test?

    In addition to what @jkotas suggestion I also sent you email with System.Configuration.ConfigurationManager.6.0.1.nupkg package built from 6.0 branch with the fixes

  15. buyaa-n commented on Jul 13, 2022

    @buyaa-n
    Contributor

    @RussKie please let us know your test result so that we can complete the servicing request

  16. modified the milestones: 7.0.0, 6.0.x on Jul 13, 2022
  17. RussKie commented on Jul 22, 2022

    @RussKie
    Contributor

    Thank you @buyaa-n.

    I installed 7.0.100-rc.1.22371.1 available at https://github.com/dotnet/installer, and tested the repro provided in https://github.com/tracktownsoftware/MicrosoftWinFormsDesignerSDK_AppSettingsBug. I created a Windows Forms app targeting .NET 7 and referenced the built NuGet from the repro project.

    The issue is fixed:

    70318.mp4
  18. RussKie commented on Jul 22, 2022

    @RussKie
    Contributor

    I have also retested the repro from #56897 (comment), and it also appears to be fixed by this.

    🎉

  19. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 22, 2022
  20. buyaa-n commented on Jul 22, 2022

    @buyaa-n
    Contributor

    Thanks @RussKie, updated the servicing PR description as needed, will send out servicing request email on Monday

  21. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Aug 11, 2022
  22. ghost locked as resolved and limited conversation to collaborators on Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions