Can anyone help me?
I had a simple code:
private void ObterRelatorios(string id) {
var relatorios = new Dictionary<string, string>();
var xml = new XmlDocument();
xml.Load("my_path");
foreach (XmlNode node in relatoriosStaticos.DocumentElement.ChildNodes)
relatorios.Add(node.Attributes["Titulo"].InnerText, string.Concat(node.Attributes["Url"].InnerText, id));
}
My xml is quite simple with 5 nodes and always is the same.
This is wierd because sometimes works, sometimes not.
This is what I get when throw an exception
Error Details:
Exception of type 'System.Web.HttpUnhandledException' was thrown.
Full Stack:
[ArgumentNullException: Value cannot be null.
Parameter name: key]
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.Dictionary.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary.Add(TKey key, TValue value)
The error says “[ArgumentNullException: Value cannot be null. Parameter name: key]”
The value for:
node.Attributes["Titulo"].InnerTextapparently is null in some cases, and this is not allowed. The key for a dictionary entry cannot be null.