'Reference to a non-shared member requires an object reference' after adding a new value to Application Settings

moris27 56 Reputation points
2023-06-19T21:14:22.8133333+00:00

If I add a new settings to my application Settings(VB.NET,NET 4.7.2),I got 142 errors:

`BC30469	Reference to a non-shared member requires an object reference`

on every code that uses My.Settings

If I use notepad++ and manually add the new value to Settings.Designer.vb and Settings.settings,there is no error

that worked fine,I think the problem is form recent VS updates

thanks for any clue

Settings.Designer.vb:

'------------------------------------------------------------------------------

' <auto-generated>

'     This code was generated by a tool.

'     Runtime Version:4.0.30319.42000

'

'     Changes to this file may cause incorrect behavior and will be lost if

'     the code is regenerated.

' </auto-generated>

'------------------------------------------------------------------------------



Option Strict On

Option Explicit On





Namespace My

    

    <Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(),  _

     Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.6.0.0"),  _

     Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)>  _

    Partial Friend NotInheritable Class Settings

        Inherits Global.System.Configuration.ApplicationSettingsBase

        

        Private Shared defaultInstance As Settings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()),Settings)

....        



    <Global.Microsoft.VisualBasic.HideModuleNameAttribute(),  _

     Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _

     Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()>  _

    Friend Module MySettingsProperty

        

        <Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")>  _

        Friend ReadOnly Property Settings() As Global.Application.My.Settings

            Get

                Return Global.Application.My.Settings.Default

            End Get

        End Property

    End Module

End Namespace

Settings.settings :

<?xml version='1.0' encoding='utf-8'?>

<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="" GeneratedClassName="Settings">

  <Profiles />

  <Settings>

    <Setting Name="Server_Name" Type="System.String" Scope="User">

      <Value Profile="(Default)">localhost</Value>

...

</Settings>

</SettingsFile>
Developer technologies VB
Developer technologies Visual Studio Other
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-06-20T05:52:17.1033333+00:00

    Hi @moris27 ,

    It is possible that an update to Visual Studio caused it to not resolve old settings correctly.

    You can try to modify your project to the same format as the new project.

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Wayne 0 Reputation points
    2023-11-16T06:58:57.5666667+00:00

    Recently I encounter same error while converting a project from VS2019 to VS2022, I use below method to solve it:

    Search for keyword "My.Settings", replace all with "My.MySettingsProperty.Settings".

    That's all.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.