向应用程序设置添加新值后,“对非共享成员的引用需要对象引用”

问题描述 投票:0回答:1

如果我向应用程序设置(VB.NET、NET 4.7.2)添加新设置,我会收到 142 个错误:

BC30469 对非共享成员的引用需要对象引用

在每个使用

My.Settings

的代码上

如果我使用notepad++并手动将新值添加到

Settings.Designer.vb
Settings.settings
,则不会出现错误

效果很好,我认为问题出在最近的 VS 2022 更新

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

设置.设置:

<?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>
.net vb.net visual-studio-2022 .net-4.7.2
1个回答
0
投票

解决此问题的简单方法是从项目更新程序添加的 Settings.Designer.vb 文件中删除“Namespace My”及其关联的 End Namespace。

© www.soinside.com 2019 - 2024. All rights reserved.