.net – Visual Studio 2010: Properties.Settings broken after retargetting project to .NET Framework 3.5

.net-3.5netvisual studio 2010

i've changed a project to target

  • .NET Framework 3.5

rather than

  • .NET Framework 4.

The project now crashes whenever i try to access settings:

Settings.Designer.cs:

      return ((global::System.Drawing.Font)(this["DefaultFont"]));

With the exception on `global::System.Drawing.Font)(this["DefaultFont"]));

An error occurred creating the configuration section handler for applicationSettings/GrobManagementSystem.Properties.Settings: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified. (C:\Develop\Contoso\GrobFrobberemphasized text\GrobManagementSystem\GrobManagementSystem\bin\Debug\GrobManagementSystem.vshost.exe.config line 8)

The problem is that the MyApp.exe.config contains references to .NET Framework 4.0 (4.0.0.0):

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" 
              type="System.Configuration.UserSettingsGroup, System, 
                    Version=4.0.0.0, 
                    Culture=neutral, PublicKeyToken=b77a5c561934e089">

This file is generated on every build, and it based on the contents of Settings.settings (an xml file that doesn't mention 4.0.0.0 anywhere):

<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="GrobManagementSystem.Properties" GeneratedClassName="Settings">
  <Profiles />
  <Settings>

There's also the settings code-behind file (Settings.Designer.cs), that also doesn't mention 4.0.0.0 anywhere:

namespace GrobManagementSystem.Properties {


    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {

        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

        public static Settings Default {
            get {
                return defaultInstance;
            }
        }

Why is the generated MyApp.exe.config referencing .NET 4.0 (i.e. 4.0.0.0), when the project isn't 4.0:

enter image description here

and the designers aren't 4.0?

And the larger question:

How do i retarget a project to .NET Framework 3.5 from .NET Framework 4.0?

Best Answer

Found the answer, delete app.config.

app.config is automatically created based on settings.settings. Visual Studio was not building it, even though it needed to be updated.

Note: Clean and rebuild doesn't force visual studio to clean and rebuild it

Deleting it, to force Visual Studio to rebuild, it fixed it.