added keu value to key not found exception (#15201)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Fri, 24 Nov 2017 23:49:35 +0000 (15:49 -0800)
committerDan Moseley <danmose@microsoft.com>
Fri, 24 Nov 2017 23:49:35 +0000 (15:49 -0800)
src/mscorlib/Resources/Strings.resx
src/mscorlib/shared/System/Collections/Generic/Dictionary.cs
src/mscorlib/shared/System/Diagnostics/Tracing/TraceLogging/EventPayload.cs
src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs
src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs
src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs
src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs
src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs
src/mscorlib/src/System/ThrowHelper.cs

index b975448..d39dc57 100644 (file)
   <data name="Arg_KeyNotFound" xml:space="preserve">
     <value>The given key was not present in the dictionary.</value>
   </data>
+    <data name="Arg_KeyNotFoundWithKey" xml:space="preserve">
+    <value>The given key '{0}' was not present in the dictionary.</value>
+  </data>
   <data name="Arg_LongerThanDestArray" xml:space="preserve">
     <value>Destination array was not long enough. Check the destination index, length, and the array's lower bounds.</value>
   </data>
index 5b57697..8792119 100644 (file)
@@ -212,7 +212,7 @@ namespace System.Collections.Generic
             {
                 int i = FindEntry(key);
                 if (i >= 0) return entries[i].value;
-                ThrowHelper.ThrowKeyNotFoundException();
+                ThrowHelper.ThrowKeyNotFoundException(key);
                 return default(TValue);
             }
             set
index 5967ad6..e67d516 100644 (file)
@@ -53,7 +53,7 @@ namespace System.Diagnostics.Tracing
                     position++;
                 }
 
-                throw new System.Collections.Generic.KeyNotFoundException();
+                throw new System.Collections.Generic.KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
             }
             set
             {
index e1593e3..1f4543e 100644 (file)
@@ -652,7 +652,7 @@ namespace System.Collections.Concurrent
                 TValue value;
                 if (!TryGetValue(key, out value))
                 {
-                    ThrowKeyNotFoundException();
+                    ThrowKeyNotFoundException(key);
                 }
                 return value;
             }
@@ -669,9 +669,9 @@ namespace System.Collections.Concurrent
         // of important methods like TryGetValue and ContainsKey.
 
         [MethodImpl(MethodImplOptions.NoInlining)]
-        private static void ThrowKeyNotFoundException()
+        private static void ThrowKeyNotFoundException(object key)
         {
-            throw new KeyNotFoundException();
+            throw new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
         }
 
         [MethodImpl(MethodImplOptions.NoInlining)]
index 188d103..85b6c39 100644 (file)
@@ -100,7 +100,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (!found)
             {
-                Exception e = new KeyNotFoundException(SR.Arg_KeyNotFound);
+                Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
                 e.SetErrorCode(HResults.E_BOUNDS);
                 throw e;
             }
index 0a6f6e0..9963630 100644 (file)
@@ -40,7 +40,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (!keyFound)
             {
-                Exception e = new KeyNotFoundException(SR.Arg_KeyNotFound);
+                Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
                 e.SetErrorCode(HResults.E_BOUNDS);
                 throw e;
             }
@@ -95,7 +95,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (!removed)
             {
-                Exception e = new KeyNotFoundException(SR.Arg_KeyNotFound);
+                Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
                 e.SetErrorCode(HResults.E_BOUNDS);
                 throw e;
             }
index 4fbcd99..47b6148 100644 (file)
@@ -111,7 +111,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             catch (Exception ex)
             {
                 if (HResults.E_BOUNDS == ex._HResult)
-                    throw new KeyNotFoundException(SR.Arg_KeyNotFound);
+                    throw new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
                 throw;
             }
         }
index 64d16ab..c554ee7 100644 (file)
@@ -39,7 +39,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (!keyFound)
             {
-                Exception e = new KeyNotFoundException(SR.Arg_KeyNotFound);
+                Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
                 e.SetErrorCode(HResults.E_BOUNDS);
                 throw e;
             }
index c3dc2c4..ae3fe98 100644 (file)
@@ -120,9 +120,9 @@ namespace System
             throw GetAddingDuplicateWithKeyArgumentException(key);
         }
 
-        internal static void ThrowKeyNotFoundException()
+        internal static void ThrowKeyNotFoundException(object key)
         {
-            throw new KeyNotFoundException();
+            throw new KeyNotFoundException(key.ToString());
         }
 
         internal static void ThrowArgumentException(ExceptionResource resource)