Form Settings Not Working

Chris M

Feb 15, 2021
Programming Experience

I'm using Visual Studio Community 2019 on Windows 10 and I'm having a major problem with Form Settings (in My Project window). It's telling me to 'click here' to create a settings file and doing so throws the following exception:

The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

I've tried importing an old (Visual Basic Express 2008) settings file and while this partially works - I get the settings I want - it keeps throwing a different exception because it thinks the settings.settings xml is corrupt.

Can anyone help?

Thanks for looking at this,

Chris M
I can confirm the exception with latest VS 16.8.5 for project type VB Winforms (.Net) which is .Net 5, and that it worked in previous VS update.
What you can do is to add a new settings file to the My Project node (right click, Add, settings file in general category) and name it Settings.settings, then it will open in project properties Setting page also.
Looks like there are more problems with this, the generated code is not right. I tried adding the My namespace to file properties in solution explorer without resolve. It also generates a different class name "Settings" in designer generated code instead of "MySettings" like it used to.
It was actually My.Resources I was testing a short while back, and didn't look at My.Settings.
According to this article "the settings feature is not yet fully implemented in the new WinForms Designer for Visual Basic".
You know you can create a .Net Framework project where My.Settings will work? .Net 5 support for VB is still in development.
Thanks for looking at this JohnH, I really appreciate it.

I tried to add a new settings.settings file, as suggested and it worked up to a point: the file was created and I added new setting but it throws an error (possible corrupt xml as above) and the code referencing it causes an exception too when run.

It seems I'm going to have to wait for the settings feature to be fully implemented before I can continue with my project - I've already waited for the new forms designer because I'm using a HD Display.

I'm afraid I'm completely ignorant when it comes to a .Net Framework Project - what's the difference, if any?


Chris M
The winforms (.Net) project is for next generation development with .Net 5, it is not ready yet. Only (barely) windows forms project type has been released so far for VB.
Projects marked (.Net framework) uses the older .Net versions up to .Net 4.8, here you'll find the full catalog of project types.
Had a look and it does solve the settings problem. Unfortunately it also reintroduces the HD Display problem, so I will just check once or month or so for updates.

Thanks again for your help,

Chris M
I've been looking the high DPI Support you mentioned but I'm having some bother with it. The Microsoft Doc 'Configuring your Windows Forms app for high DPI support' says to Declare Compatibility with Windows 10 with the following xml in the Manifest File:

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<!-- Windows 10 compatibility -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

What Manifest file? I'm probably being daft but I cannot find a Manifest file to copy the xml to?

The document then goes on to say: Enable per-monitor DPI awareness in the app.config file. This calls for adding the following xml:

<add key="DpiAwareness" value="PerMonitorV2" />

I know where the app.config file is so this bit shouldn't be troublesome.

And then, finally, to: Call the static EnableVisualStyles method with the following:

Private Shared Sub Main()
Application.Run(New Form2())
End Sub

Where do I enter this please?

Apologies if some (or all) of my questions are simple but I'm more or less new to this - used VB Express 2008 a decade ago but never touched on something like this.

Chris M
Call the static EnableVisualStyles method
It is possible you can call this in Startup event of application (View Application Events in same project properties page). If not you have to turn off application framework and setup up your own Sub Main I think.
You don't need to call EnableVisualStyles yourself, application framework calls this method when this checkbox is enabled (default)

This also is from the same project properties page.