<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>
{
int i = FindEntry(key);
if (i >= 0) return entries[i].value;
- ThrowHelper.ThrowKeyNotFoundException();
+ ThrowHelper.ThrowKeyNotFoundException(key);
return default(TValue);
}
set
position++;
}
- throw new System.Collections.Generic.KeyNotFoundException();
+ throw new System.Collections.Generic.KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
}
set
{
TValue value;
if (!TryGetValue(key, out value))
{
- ThrowKeyNotFoundException();
+ ThrowKeyNotFoundException(key);
}
return value;
}
// 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)]
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;
}
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;
}
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;
}
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;
}
}
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;
}
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)