I want to create a nested ConcurrentDictionary after parsing a large XML file. What I get when running the code below is that the innermost(tmpDictionaryDid) dictionary is null.
I guess I don't save the dictionaries properly or load them incorrectly, but I can't figure out what is incorrect.
Is it even possible to solve it with ConcurrentDictionary or should I try with another solution?
public void temp22db()
{
ConcurrentDictionary<string, ConcurrentDictionary<string, string>> dictionary22 = new ConcurrentDictionary<string, ConcurrentDictionary<string, string>>();
try
{
ConcurrentDictionary<string, string> did = new ConcurrentDictionary<string, string>();
did.TryAdd("F186 1", "test1");
did.TryAdd("F186 2", "test2");
dictionary22.TryAdd("F186", did);
did.TryAdd("EDA0 1", "test3");
did.TryAdd("EDA0 2", "test4");
dictionary22.TryAdd("EDA0", did);
string test;
did.TryGetValue("EDA0 1", out test);
Helper.logInWindow("This works " + test);
}
catch (Exception e)
{
Helper.logInWindow("SDDBTemp: " + e.Message);
}
ecuDictionary2.TryAdd("1638", dictionary22);
}
public string getDIDInterpretation()
{
string outStr = "";
ConcurrentDictionary<string, ConcurrentDictionary<string, string>> tmpDictionary;
ecuDictionary2.TryGetValue("1638", out tmpDictionary);
if (tmpDictionary != null)
{
ConcurrentDictionary<string, string> tmpDictionaryDid;
tmpDictionary.TryGetValue("EDA0", out tmpDictionaryDid);
if (tmpDictionaryDid != null)
{
tmpDictionaryDid.TryGetValue("EDA0 1", out outStr);
}
}
Helper.logInWindow("Why U no work? " + outStr);
return outStr;
}