I have declared two Public
dictionaries in a Module
as follows:
Module Globals
Public buttonImagesEnabled As Dictionary(Of Integer, Image)
Public buttonImagesDisabled As Dictionary(Of Integer, Image)
End Module
Which are then initialised in the constructor for a 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
The solution builds fine but when I try to run it, I get an exception (at the line in the form constructor specifying a New Dictionary
):
System.TypeInitializationException: 'The type initializer for 'MySolution.Globals' threw an exception.'
InnerException #1
{"Configuration system failed to initialize"}
InnerException #2
{"Unrecognized configuration section system.diagnostics. (...ProjectPath.MySolution.dll.config line 8)"}
Checked the.dll.config file and it's just a <system.diagnostics>
XML tag (the rest of the XML looks fine to me)
If I move the Public
declaration into the Form
(and out of the Module
) it runs fine but I can't access the dictionaries from any of my classes (ie referencing them in the classes produces errors á la:
'buttonImagesEnabled' is not declared. It may be inaccessible due to its protection level.
Am I missing something blindingly obvious here?
Okay, looks like it was nothing to do with the dictionaries, nor their declarations - the app.config
file was somehow botched.
The solution here: .NET Core - Using system.diagnostics in App.config solved the problem (manual insertion of the <system.diagnostics>
configSection
into the XML)
Why on earth Visual Studio / .NET Core inserts the section, but not the declaration, automatically, is absurd to me!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.