* Add the key in the message on throwing a KeyNotFoundException for trying to access an invalid key in the ResourceDictionary. This helps a lot in tracking down what resource is actually missing.
* Fix test build, use C# 6 string interpolation
elt.Parent = parent;
Assert.Fail ();
}
- }
+
+ [Test]
+ public void ShowKeyInExceptionIfNotFound()
+ {
+ var rd = new ResourceDictionary();
+ rd.Add("foo", "bar");
+ var ex = Assert.Throws<KeyNotFoundException>(() => { var foo = rd["test_invalid_key"]; });
+ Assert.That(ex.Message, Is.StringContaining("test_invalid_key"));
+ }
+ }
}
\ No newline at end of file
return _innerDictionary[index];
if (_mergedInstance != null && _mergedInstance.ContainsKey(index))
return _mergedInstance[index];
- throw new KeyNotFoundException();
+ throw new KeyNotFoundException($"The resource '{index}' is not present in the dictionary.");
}
set
{