c# - Static dictionary call "System.TypeInitializationException" -



c# - Static dictionary call "System.TypeInitializationException" -

i have static class hold dictionary , 2 methods access it

here class:

public static class configuracuadros { public static dictionary<string,dictionary<string,dictionary<string,dictionary<string,string>>>> getdictionary() { // seek result in static dictionary homecoming _configcuadros; } public static dictionary<string, dictionary<string, dictionary<string, string>>> gethoja(string key) { // seek result in static dictionary dictionary<string, dictionary<string, dictionary<string, string>>> result = new dictionary<string, dictionary<string, dictionary<string, string>>>(); if (_configcuadros.trygetvalue(key, out result)) { homecoming result; } else { homecoming null; } } public static readonly dictionary<string, dictionary<string, dictionary<string, dictionary<string, string>>>> _configcuadros = new dictionary<string, dictionary<string, dictionary<string, dictionary<string, string>>>> { { "formato01", //this hint, dictionary much more extensive new dictionary<string, dictionary<string, dictionary<string, string>>> { { "f01c01a", new dictionary<string, dictionary<string, string>> { { "x", new dictionary<string, string> { { "key1" , "value1" }, { "key2" , "value2" }, { "key3" , "value3" }, } }, } }, } }, } }`

when utilize getter method,

configuracuadros.getdictionary();

it throws exception:

first chance exception of type 'system.argumentexception' occurred in mscorlib.dll 'configuracuadros.getdictionary()' threw exception of type 'system.typeinitializationexception' base: {"the type initializer 'bedgraic.configuracuadros' threw exception."} typename: "bedgraic.configuracuadros"

or

'configuracuadros.gethoja("formato01")' threw exception of type 'system.typeinitializationexception' base: {"the type initializer 'bedgraic.configuracuadros' threw exception."} typename: "bedgraic.configuracuadros"

as can see, intention have static dictionary. think problem in dictionary declaration ... can't see where...

just in case, "bedgraic" namespace.

thanks help!

your code works (almost) me.

i added missing semi-colon compile can phone call configuracuadros.getdictionary(); without exception.

here code missing semicolon:

public static class configuracuadros { public static dictionary<string, dictionary<string, dictionary<string, dictionary<string, string>>>> getdictionary() { // seek result in static dictionary homecoming _configcuadros; } public static dictionary<string, dictionary<string, dictionary<string, string>>> gethoja(string key) { // seek result in static dictionary dictionary<string, dictionary<string, dictionary<string, string>>> result = new dictionary<string, dictionary<string, dictionary<string, string>>>(); if (_configcuadros.trygetvalue(key, out result)) { homecoming result; } else { homecoming null; } } public static readonly dictionary<string, dictionary<string, dictionary<string, dictionary<string, string>>>> _configcuadros = new dictionary<string, dictionary<string, dictionary<string, dictionary<string, string>>>> { { "formato01", //this hint, dictionary much more extensive new dictionary<string, dictionary<string, dictionary<string, string>>> { { "f01c01a", new dictionary<string, dictionary<string, string>> { { "x", new dictionary<string, string> { { "key1" , "value1" }, { "key2" , "value2" }, { "key3" , "value3" }, } }, } } } } }; }

[update]

i agree comments above checking out innerexception general rule type initialisation exception and, particularly, unfriendly nature of datatype!

c# .net dictionary static-classes static-class

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -