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

Setting do not work on NEW VB .Net 5 Winforms application #7448

Closed
paul1956 opened this issue May 22, 2021 · 22 comments
Closed

Setting do not work on NEW VB .Net 5 Winforms application #7448

paul1956 opened this issue May 22, 2021 · 22 comments
Assignees
Labels
Area-VisualBasic Specific to the VB.NET language. Feature-Settings-Designer Specific to the settings file designer. Triage-Investigate Reviewed and investigation needed by dev team
Milestone

Comments

@paul1956
Copy link

  • .NET Core Version: What I have installed is below
Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0-preview.2.21154.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  • Have you experienced this same bug with .NET Framework?:
    No

Problem description:
Create a new VB WinForm App, that will read settings, add settings, run app and application will crash as below.

image

System.Configuration.ConfigurationErrorsException
  HResult=0x80131902
  Message=Configuration system failed to initialize
  Source=System.Configuration.ConfigurationManager
  StackTrace:
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
   at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.RefreshConfig(String sectionName)
   at System.Configuration.ConfigurationManager.RefreshSection(String sectionName)
   at System.Configuration.ClientSettingsStore.ReadSettings(String sectionName, Boolean isUserScoped)
   at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
   at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
   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 CareLink.My.MySettings.get_username() in C:\Users\PaulM\Source\Repos\CareLink\CareLink\My Project\Settings.Designer.vb:line 62
   at CareLink.LoginForm1.LoginForm1_Load(Object sender, EventArgs e) in C:\Users\PaulM\Source\Repos\CareLink\CareLink\LoginForm1.vb:line 12
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
ConfigurationErrorsException: Unrecognized configuration section system.diagnostics. (C:\Users\PaulM\Source\Repos\CareLink\CareLink\bin\Debug\net5.0-windows\CareLink.dll.config line 8)

Expected behavior:
I can read settings

Minimal repro:
Contents of .config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" >
            <section name="CareLink.My.MySettings" type="System.Configuration.ClientSettingsSection, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>

Manually deleting system.diagnostics section fixes the issue until a rebuild.

    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information" />
        </switches>
        <sharedListeners>
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>

From here down works

    <userSettings>
        <CareLink.My.MySettings>
            <setting name="username" serializeAs="String">
                <value />
            </setting>
            <setting name="password" serializeAs="String">
                <value />
            </setting>
        </CareLink.My.MySettings>
    </userSettings>
</configuration>
@KlausLoeffelmann
Copy link
Member

Hey Paul, thanks for reporting this.
And also thank you for providing that workaround.

Project System knows about general issues with conflicting Framework/.NET Core/5 assembly versions, and we're working on a solution.

@KathleenDollard for FYI!

@paul1956
Copy link
Author

@KlausLoeffelmann, it seems if you delete the problem sections from App.Config manually. You can change setting and the changes work at runtime and the error doesn't happen of course you lose the features you comment out (Logging).

@RussKie
Copy link
Member

RussKie commented Jun 16, 2021

Project System knows about general issues with conflicting Framework/.NET Core/5 assembly versions, and we're working on a solution.

@KlausLoeffelmann is this tracked somewhere to which we can link?

@paul1956
Copy link
Author

I just ported a 10 year old WinForm app to .Net Core 5 using TryConvert. It used SQL, Excel and Office Interop and it went flawlessly except for the issue with App.Config any update on when this might be fixed, what does external issue mean? Also found a subtle bug in the code flagged by newest ,Net analyzers.

@RussKie
Copy link
Member

RussKie commented Jul 21, 2021

what does external issue mean?

It means just that, the issue is external to our codebase.

@KlausLoeffelmann the stack trace in https://github.com/dotnet/winforms-designer/issues/3596 looks very similar.

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

@RussKie RussKie transferred this issue from dotnet/winforms Jul 21, 2021
@ghost
Copy link

ghost commented Jul 21, 2021

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

Issue Details
  • .NET Core Version: What I have installed is below
Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0-preview.2.21154.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  • Have you experienced this same bug with .NET Framework?:
    No

Problem description:
Create a new VB WinForm App, that will read settings, add settings, run app and application will crash as below.

image

System.Configuration.ConfigurationErrorsException
  HResult=0x80131902
  Message=Configuration system failed to initialize
  Source=System.Configuration.ConfigurationManager
  StackTrace:
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
   at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.RefreshConfig(String sectionName)
   at System.Configuration.ConfigurationManager.RefreshSection(String sectionName)
   at System.Configuration.ClientSettingsStore.ReadSettings(String sectionName, Boolean isUserScoped)
   at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
   at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
   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 CareLink.My.MySettings.get_username() in C:\Users\PaulM\Source\Repos\CareLink\CareLink\My Project\Settings.Designer.vb:line 62
   at CareLink.LoginForm1.LoginForm1_Load(Object sender, EventArgs e) in C:\Users\PaulM\Source\Repos\CareLink\CareLink\LoginForm1.vb:line 12
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
ConfigurationErrorsException: Unrecognized configuration section system.diagnostics. (C:\Users\PaulM\Source\Repos\CareLink\CareLink\bin\Debug\net5.0-windows\CareLink.dll.config line 8)

Expected behavior:
I can read settings

Minimal repro:
Contents of .config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" >
            <section name="CareLink.My.MySettings" type="System.Configuration.ClientSettingsSection, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>

Manually deleting system.diagnostics section fixes the issue until a rebuild.

    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information" />
        </switches>
        <sharedListeners>
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>

From here down works

    <userSettings>
        <CareLink.My.MySettings>
            <setting name="username" serializeAs="String">
                <value />
            </setting>
            <setting name="password" serializeAs="String">
                <value />
            </setting>
        </CareLink.My.MySettings>
    </userSettings>
</configuration>
Author: paul1956
Assignees: KlausLoeffelmann
Labels:

area-System.Configuration, untriaged

Milestone: -

@RussKie
Copy link
Member

RussKie commented Jul 21, 2021

This issue is blocking migration scenarios.

@safern
Copy link
Member

safern commented Jul 21, 2021

cc @dotnet/area-system-configuration

@buyaa-n
Copy link

buyaa-n commented Jul 21, 2021

Probably related to dotnet/runtime#931, cc @JeremyKuhne

@paul1956 could you try the workaround mentioned here dotnet/runtime#931 (comment)?

@RussKie
Copy link
Member

RussKie commented Jul 22, 2021

@buyaa-n this needs to be fixed in .NET 6.0 timeframe (and possibly serviced in .NET 5.0 and 3.1?). This is a regression which is blocking migration scenarios.

@paul1956
Copy link
Author

@buyaa-n I read the workaround multiple times and I don't see what I need to do. I don't have any code that looks like that.
The first time I read any setting the program crashes at the line below with an error.

        <Global.System.Configuration.ApplicationScopedSettingAttribute(),  _
         Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _
         Global.System.Configuration.SpecialSettingAttribute(Global.System.Configuration.SpecialSetting.ConnectionString),  _
         Global.System.Configuration.DefaultSettingValueAttribute("Data Source=.\SQLEXPRESS;Initial Catalog=VolunteerHours;Integrated Security=True;"& _ 
            "Pooling=False")>  _
        Public ReadOnly Property masterConnectionString() As String
            Get
                Return CType(Me("masterConnectionString"),String) ' <------ ERROR
            End Get
        End Property

@danmoseley
Copy link
Member

@paul1956 am I correct that you don't need the <system.diagnostics> section? ie., you can build, remove that section, and deploy your app without it and you're fine with that -- the problem is that it puts it back when you rebuild?

If so, perhaps this is something that the project system should not add for .NET Core based projects.

@paul1956
Copy link
Author

paul1956 commented Jul 27, 2021

@danmoseley I only use userSettings. If I edit the APPLICATIONNAME.dll.config file and delete the 2 problem sections they come back when I rebuild. If I edit the application.config file the issue doesn't come back for that project. The problem happens in two scenarios, "New Projects" where the project system adds the Diagnostic and Switches sections and at least initially they are not used and may never be so deleting it should not be an issue, and ported projects (either manually or with TryConvert). In the TryConvert and manual porting scenario the data in Version and PublicKeyToken are wrong (it is 4.0.0.0 or less and has a different PublicKeyToken) and unless you read this thread you have no idea where to get the values.

<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" >

I don't know what switches does so it might work or not, Logging might work if I knew how to set the Type Line above.

Related issue is, it fails pointing to perfectly valid code (that I need) making it even more difficult to diagnose.

@buyaa-n
Copy link

buyaa-n commented Jul 27, 2021

@buyaa-n I read the workaround multiple times and I don't see what I need to do. I don't have any code that looks like that.

@paul1956 sorry the workaround mentioned was in the above comment, here is the exact comment i wanted to read:

Do we have a customer report about what people end up doing to make this work today?

They are having to rewrite their code or copy over the shared test app.config on the box.

But it might not be directly be related to your issue, looks like it is more related to the @RussKie's exception log.

Your issue (error log) might be related to dotnet/runtime#32307 and I am not sure if there is a workaround cc @eerhardt

@paul1956
Copy link
Author

@buyaa-n I currently don't have apps that use exception log, I am working on a consumer medical display application where it would be very useful but as I said here the information to get it to work is missing. Where do I find "copy over the shared test app.config". All the app.config files that get installed with .Net have similar issues.

@eerhardt eerhardt transferred this issue from dotnet/runtime Jul 30, 2021
@eerhardt
Copy link
Member

eerhardt commented Jul 30, 2021

I was able to reproduce this on a new .NET 5 VB WinForms app. You just need to "Add => New Item" and choose a "Settings" item. Add a new string setting named "username", and then add code to read the "username" property of a "new Settings1" object.

The system.diagnostics section isn't a valid app.config section in .NET 5. The runtime doesn't get configured by app.config in .NET 5 like it did in .NET Framework.

Moving to dotnet/project-system since this is a tooling issue, and not a runtime issue. The tooling shouldn't be generating this section.

cc @swesonga @jjmew

@danmoseley
Copy link
Member

Hello project system friends, it would be great if you could take a look at this one as it is a migration blocker for some VB customers.

@jjmew
Copy link
Contributor

jjmew commented Aug 2, 2021

@melytc Can you take a look at this? maybe get some context from @tmeschter

@danmoseley
Copy link
Member

cc @KathleenDollard this is a case where tooling apparently breaks upgrade of a VB app. It's writing extra stuff to the config that the runtime won't use, so the config system rejects it.

@jjmew jjmew added the Triage-Investigate Reviewed and investigation needed by dev team label Aug 24, 2021
@jjmew jjmew added this to the 17.1 milestone Aug 24, 2021
@jjmew jjmew added the Area-VisualBasic Specific to the VB.NET language. label Aug 24, 2021
@drewnoakes drewnoakes added the Feature-Settings-Designer Specific to the settings file designer. label Sep 9, 2021
@drewnoakes drewnoakes removed this from the 17.1 milestone Dec 3, 2021
@drewnoakes drewnoakes added this to the 17.2 milestone Dec 3, 2021
@elGuille-info
Copy link

elGuille-info commented Dec 24, 2021

As @paul1956 I have the same issues in .NET 6 and using "My.Settings".
I first had the error when adding a new value to the setting section (Project>Properties>Setting section), then run the project and got the same error as Paul.

First workaround is deleting the app.config file, then run the project and works fine.

Now, reading the Paul's workaround, instead of delete the <system.diagnostics> I comment it and now all is working.

If I add or remove a value from settings, I didn't have any error, and the values are added (or deleted) from the app.config file and the commented section remains commented.

Hope it's help.

Guillermo

P.S.
To clarify: I start a new project and don't use any "upgrade tool".

@ocallesp
Copy link
Contributor

The PR https://devdiv.visualstudio.com/DevDiv/_git/VS/pullrequest/403807 should handle the issue in system.diagnostics

@RussKie
Copy link
Member

RussKie commented Jul 20, 2022

FYI, system.diagnostics section is not being recognised because this section no longer being registered. More information can be found here dotnet/runtime#23937 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VisualBasic Specific to the VB.NET language. Feature-Settings-Designer Specific to the settings file designer. Triage-Investigate Reviewed and investigation needed by dev team
Projects
None yet
Development

Successfully merging a pull request may close this issue.