[英]Public dictionary not visible to class
我在一個Module
中聲明了兩個Public
字典,如下所示:
Module Globals
Public buttonImagesEnabled As Dictionary(Of Integer, Image)
Public buttonImagesDisabled As Dictionary(Of Integer, Image)
End Module
然后在Form
的構造函數中對其進行初始化:
Public Class myForm
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
buttonImagesEnabled = New Dictionary(Of Integer, Image)
buttonImagesDisabled = New Dictionary(Of Integer, Image)
End Sub
End Class
該解決方案構建得很好,但是當我嘗試運行它時,我得到了一個異常(在表單構造函數中指定一個New Dictionary
的行):
System.TypeInitializationException:“'MySolution.Globals' 的類型初始化程序引發了異常。”
內部異常 #1
{"配置系統初始化失敗"}
內部異常 #2
{“無法識別的配置部分 system.diagnostics。(...ProjectPath.MySolution.dll.config 第 8 行)”}
Checked the.dll.config file and it's just a <system.diagnostics>
XML tag (the rest of the XML looks fine to me)
如果我將Public
聲明移入Form
(並移出Module
),它運行良好,但我無法從我的任何類中訪問字典(即在類中引用它們會產生錯誤 á la:
'buttonImagesEnabled' 未聲明。 由於其保護級別,它可能無法訪問。
我在這里錯過了一些非常明顯的東西嗎?
好的,看起來這與字典無關,也與它們的聲明無關 - app.config
文件不知何故被搞砸了。
這里的解決方案: .NET Core - Using system.diagnostics in App.config解決了問題(手動將<system.diagnostics>
configSection
插入 XML)
為什么 Visual Studio / .NET Core 自動插入部分,而不是聲明,這對我來說是荒謬的!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.