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

Creating/Saving a Settings file throws error #3346

Closed
docfresh opened this issue May 26, 2020 · 37 comments
Closed

Creating/Saving a Settings file throws error #3346

docfresh opened this issue May 26, 2020 · 37 comments
Assignees
Labels
area-VSDesigner Windows Forms out-of-proc designer related issues tracking-external-issue An issue is caused by an external system and won't be fixed in this repo

Comments

@docfresh
Copy link

  • .NET Core Version:
    3.1

  • Have you experienced this same bug with .NET Framework?:
    No

Problem description:
I used try-convert to convert a near-empty .NET 4.72 Framework project to .NET Core.

When trying to add a settings file, I get the error "An error occurred while reading the app. config file. The file might be corrupted or contain invalid XML" when creating a new Settings file and saving it. I also get the error "The Method or operation is not implemented" when clicking the "View Code" button. The settings do seem to work though.

Even if I delete and recreate the settings file, I still get the error.

image

Expected behavior:
Don't get an error.

Minimal repro:

  1. Create new WinForms .NET Core project.
  2. Solution Explorer -> Right Click -> Add
  3. Search for "Settings File"
  4. Create Settings File and add one boolean setting with a default value of False
  5. Get the error message
@RussKie RussKie added the area-VSDesigner Windows Forms out-of-proc designer related issues label May 26, 2020
@RussKie
Copy link
Member

RussKie commented May 26, 2020

@docfresh I appreciate you have spent the time to raise the issue, but issues with VS and VS Designer should be sent via VS Feedback channel (the icon in the top right hand side corner). The reason for this - the VS Feedback tool captures a lot of additional information (such as screenshots, memory dumps, stack traces, assembly versions, etc.) that can help us to investigate your issue and identify the cause.

@merriemcgaw
Copy link
Member

Just to let you know, this issue has not yet been implemented by the team. We have it high on our backlog and look forward to having it available in an upcoming VS preview. I'll circle back and let you know when we've gotten the work done.

Designer issue (sorry this isn't public at this point, just linking for internal reference)

@paul1956
Copy link
Contributor

@merriemcgaw could we create a single list (issue) for all the things that are know to be broken with VB and Designer. It would save a lot of reporting and then we would know what issue we find that should be added. This was done initially for VB Core and in that case others could contribute. For example I don't see that the designer corrupts VB Project files that have local Custom Control or that it adds a namespace to designer.vb file for each local User Control reference. I believe both of these things are not supported by observation but you don't get that from the blog of what IS supported.

@RussKie
Copy link
Member

RussKie commented May 28, 2020

Providing you with a list would not be productive - the list is constantly changing. But the team looks at all issues that are raised via the VS Feedback (the icon in the top right hand side corner). And this is one of the reasons why issues with VS and VS Designer should be sent via the VS Feedback.
Another reason - the VS Feedback tool captures a lot of additional information (such as screenshots, memory dumps, stack traces, assembly versions, etc.) that can help us to investigate these issue and identify underlying causes.

@docfresh
Copy link
Author

docfresh commented May 28, 2020

@RussKie my apologies, I will use VS Feedback in the future. FYI I made a linked issue on the try-convert project here; they are adding a warning about app.config
dotnet/try-convert#296

@paul1956
Copy link
Contributor

@RussKie stock answer from Feedback is VB is not supported by Designer even though it has been, to some extent, since VSIX preview and they close the issue but I will continue to use that method. I didn't want to bother on issues that are known to not work.

@merriemcgaw merriemcgaw added this to the VS release milestone Jun 4, 2020
@paul1956
Copy link
Contributor

paul1956 commented Oct 3, 2020

I would like to add additional information, there are two related issues. If a valid settings.Designer.VB files exists you get the error above. If there is no settings.Designer.VB File there is message/link on the Settings screen "The project does not contain a default settings file. Click here to create one". Followed by the error message shown when you click.

https://files.gitter.im/59b31bd6d73408ce4f74f5b4/wuqh/image.png
image

@merriemcgaw
Copy link
Member

@KlausLoeffelmann should be able to update us on the current state of VB support in .NET 5/Visual Studio. We're making a lot of progress there.

@KlausLoeffelmann
Copy link
Member

For C#: Settings work just fine for me in WinForms. I can add Settings, if they don't exist, and I can edit Settings. Also the Code Generator producing the Setting.Designer.cs is working just fine.
For VB: True, we cannot create a settings file. But you can manually insert a file at the correct location as a work around for now. Also true, you are getting the said error message on opening and saving, but serialization, deserialization, editing and code generation should work anyway. @jjmew and @KathleenDollard for that as well.

@paul1956
Copy link
Contributor

Not sure I followed directions correctly, but I creates Settings.settings, filled it out using VS UI, saved and built, I now get

Error Failed to generate file: The type name:"FindWordApp.FindWordApp.My Project.MySettings" on the property:"BaseType" of type:"System.CodeDom.CodeTypeReference" is not a valid language-independent type name.
Parameter name: typeName

@KlausLoeffelmann
Copy link
Member

3.1 or 5? C# or VB?

@paul1956
Copy link
Contributor

paul1956 commented Oct 10, 2020

5 VB, I don't even try with 3.1. I only saw this today when I moved a new app to Core 5 and noticed "My.Settings" type was missing. For Core 3, I have a shim that I hoped was not necessary with Core 5 so I deleted shim (below) and changed a setting so settings would be regenerated.

Namespace My

    <HideModuleName(),
     DebuggerNonUserCode(),
     Runtime.CompilerServices.CompilerGenerated()>
    Friend Module MySettingsProperty

        <ComponentModel.Design.HelpKeyword("My.Settings")>
        Friend ReadOnly Property Settings() As Settings
            Get
                Return Settings.Default
            End Get
        End Property

    End Module
End Namespace

If I delete Settings.Designer.VB, a new app.config file is created with entries I am not familiar with. So the missing App.Config issue goes away but Settings.Designer.Vb is not created but I still get
image

@paul1956
Copy link
Contributor

paul1956 commented Oct 10, 2020

App.Config file that gets created

<?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="FindWordApp.MySettings" type="System.Configuration.ClientSettingsSection, System.Configuration.ConfigurationManager, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <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>
    <userSettings>
        <FindWordApp.MySettings>
            <setting name="TextBox1" serializeAs="String">
                <value />
            </setting>
            <setting name="TextBox2" serializeAs="String">
                <value />
            </setting>
            <setting name="TextBox3" serializeAs="String">
                <value />
            </setting>
            <setting name="TextBox4" serializeAs="String">
                <value />
            </setting>
            <setting name="TextBox5" serializeAs="String">
                <value />
            </setting>
            <setting name="TextBox6" serializeAs="String">
                <value />
            </setting>
            <setting name="TextBox7" serializeAs="String">
                <value>A</value>
            </setting>
            <setting name="UpgradeRequired" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="LettersInPlay" serializeAs="String">
                <value>5</value>
            </setting>
            <setting name="WordLength" serializeAs="String">
                <value>5</value>
            </setting>
            <setting name="PrimingWord" serializeAs="String">
                <value>Hello</value>
            </setting>
        </FindWordApp.MySettings>
    </userSettings>
</configuration>

If this file exists you get a runtime exception trying to access UpgradeRequired

@paul1956
Copy link
Contributor

@KlausLoeffelmann if settings are not going to be fixed for release (since its priority 2), can someone provide documentation on what is expected in empty App.Config so designer works and what workaround is needed to expose Settings to application. Will #3346 (comment) still work and if not what is needed?

There are 2 different scenarios that both have issues;

  1. New project wanting settings
  2. Existing Framework project that has settings.designer but no app.config file.

@paul1956
Copy link
Contributor

@RussKie @KlausLoeffelmann @Zheng-Li01 @merriemcgaw Update with Preview 2, Core 5, you still can't create new setting file, if one exists from Framework you get same error while trying to open but it does open.
image
You can edit but then you get errors in output window (there is an extra NameSpace ) and it does not overwrite existing Settings.design.vb which has no errors.
image
The only way to resolve errors is to close Visual Studio. After reopening Setting.Settings has all the changes and .Designer has original content without any of the changes.

@merriemcgaw
Copy link
Member

We're still working on the Settings files and what should happen with app.config files. We will keep you posted.

@chayaphon
Copy link

Hi, I just download VS2019 latest version, and when I create new project both .Net5 and .Net Core 3.1 still found the same issue...
is there any update ?

@merriemcgaw
Copy link
Member

This is on our backlog of features we want to get into the next release, but we've got a lot of competing priorities so I'm not quite able to commit to a particular release at this time.

@paul1956
Copy link
Contributor

paul1956 commented Jun 16, 2021

Is there any workaround? Is App.Config still used? updating Settings does not update it but the changed settings seem to work in the application.

@merriemcgaw
Copy link
Member

Adding @JeremyKuhne to see what his thoughts are for an alternative approach,

@KlausLoeffelmann
Copy link
Member

Yes, for the time being, we will keep app.config.

As a workaround:
The type version of the UserSettingsGroup class in the app config should be changed to Version=4.0.0.0 and it’s assembly to System.

That should solve the problems for runtime and designer.

@paul1956
Copy link
Contributor

@KlausLoeffelmann could we have a specific example the first doesn't help and the second is an error

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

@paul1956
Copy link
Contributor

@KlausLoeffelmann If I look at App.config, after I change a setting it does not reflect the changes. After I delete the logging section from App.Config it is never put back. In both cases the changes I make to setting (values or additional setting) do from through to the application. I don't see any way to add/change the log settings in Visual Studio other then creating a new project.

@KlausLoeffelmann
Copy link
Member

KlausLoeffelmann commented Jun 23, 2021

Well, basically what's happening is that when the App.Config gets written, the .NET (not the .NET Framework) types get written out. Which is principally OK, but: At runtime, the Framework process tries to resolve those types being stated in the app config, and of course it can't. And that's why we're seeing the errors: VS running in the Framework process can simply not deal with the types. Now, what should happen is: Deserializing the types in App.Config should be happening in the Core process (the App.Config should be send over, then be deserialized, and then proxies of the types should be being processed from that point on in the Framework (VS) process.) The question is: Do we want to continue using App.Config at all for this purpose, and how are we dealing with the backwards compatibility of types here (you updated let's say your machine to .NET 5.0.4, but your team members are not yet running that update - what version should be serialized then? 5.0? 5.0.4? And what about 6.0? Should you be able to open a 6.0 config file in a 5.0 app? Those discussions we're leading currently.

Since Framework types will be forwarded to Core in general, the workaround of putting the Framework types there is definitely working - I just tested that. I probably forgot to mention, that the PublicKeyToken needs to be adjusted accordingly to Framework as well. So, if you put these types in, everything should work for the time being:

    <configSections>
        <sectionGroup name="userSettings"
       type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="WinFormsApp1.My.MySettings"
      type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>

Can you test that if that is working for you?
Also @KathleenDollard for FYI.

(We're also need to figure out, how the settings feature will be featured in the new Project Properties UI. Currently, in the new UI, we can't create or edit settings at all, and here is an item for that in PS:
dotnet/project-system#7355)

@paul1956
Copy link
Contributor

@KlausLoeffelmann making that change causes 2 errors in designer with very clean messages about settings and App.Config differing. Accepting both seems to do everything correctly and they don't happen again. I still need to delete logging section or I get a runtime error. Should the default App.Config on new applications be upgraded to above?

    <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>

@KlausLoeffelmann
Copy link
Member

Should the default App.Config on new applications be upgraded to above?

That is a question @merriemcgaw and @KathleenDollard are discussing, currently.
I hadn't have a chance yet to get behind this.

@RussKie
Copy link
Member

RussKie commented Aug 30, 2021

In the interest of transparency, we do obviously have a number of gaps and regressions in Settings and Resource handling, but most of those lie outside the realm of our team. We are working with sister teams to identify correct owners and facilitate fixes. Unfortunately there are no ETAs of any kind at the moment.

@RussKie

This comment has been minimized.

@paul1956
Copy link
Contributor

I don't want/use logging it is just what comes over from framework.

@RussKie
Copy link
Member

RussKie commented Aug 31, 2021

@paul1956 I had a debugging session today, and discovered that the diagnostics section you mentioned in #3346 (comment) comes from a app.config template owned by Project System team. Please raise a VS Feedback issue for it. If you post the link here I can make sure it gets assigned to the area owner team.

/cc: @jjmew @drewnoakes

@drewnoakes
Copy link
Member

a app.config template owned by Project System team

The Project System does not own any templates. Are you referring to https://github.com/dotnet/templates or https://github.com/dotnet/templating?

@RussKie
Copy link
Member

RussKie commented Aug 31, 2021

@drewnoakes please refer to AB#1386445 which has some relevant details.

@RussKie
Copy link
Member

RussKie commented Aug 31, 2021

@paul1956 please see dotnet/project-system#6784

@RussKie RussKie closed this as completed Aug 31, 2021
@ghost ghost removed this from the VS release milestone Aug 31, 2021
@RussKie RussKie added tracking-external-issue An issue is caused by an external system and won't be fixed in this repo and removed Priority 2 labels Aug 31, 2021
@paul1956
Copy link
Contributor

paul1956 commented Sep 1, 2021

I am currently on a ship bound for Alaska and will lose internet shortly. I will do this next Wednesday when I return. Thanks.

@RussKie
Copy link
Member

RussKie commented Sep 1, 2021

Enjoy your trip! 🍸

@vijaysridhara
Copy link

Is this fixed yet? I just upgraded my VS 2019 for latest release 16.11.3. I am creating a new VB.NET project in VS 2019, with .NET 5.0. And it complains to even open the Project Settings panel. Whether I add new string params, they wont work. Any workaround is appreciated

@RussKie
Copy link
Member

RussKie commented Sep 23, 2021

@VitalLogic please see dotnet/project-system#6784

@ghost ghost locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VSDesigner Windows Forms out-of-proc designer related issues tracking-external-issue An issue is caused by an external system and won't be fixed in this repo
Projects
None yet
Development

No branches or pull requests

9 participants