diff options
-rw-r--r-- | Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs | 11 | ||||
-rw-r--r-- | Xamarin.Forms.Core/ResourceDictionary.cs | 2 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs b/Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs index d4229221..c4e6bbf3 100644 --- a/Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs +++ b/Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs @@ -252,5 +252,14 @@ namespace Xamarin.Forms.Core.UnitTests 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 diff --git a/Xamarin.Forms.Core/ResourceDictionary.cs b/Xamarin.Forms.Core/ResourceDictionary.cs index 791c6e5d..0747eaac 100644 --- a/Xamarin.Forms.Core/ResourceDictionary.cs +++ b/Xamarin.Forms.Core/ResourceDictionary.cs @@ -98,7 +98,7 @@ namespace Xamarin.Forms 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 { |