Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/libraries/System.Private.CoreLib/src/System/Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,8 @@ private static bool TryParseRareEnum(RuntimeType enumType, ReadOnlySpan<char> va

private static bool TryParseByName(RuntimeType enumType, ReadOnlySpan<char> value, bool ignoreCase, bool throwOnFailure, out ulong result)
{
ReadOnlySpan<char> originalValue = value;

// Find the field. Let's assume that these are always static classes because the class is an enum.
EnumInfo enumInfo = GetEnumInfo(enumType);
string[] enumNames = enumInfo.Names;
Expand Down Expand Up @@ -952,7 +954,7 @@ private static bool TryParseByName(RuntimeType enumType, ReadOnlySpan<char> valu

if (throwOnFailure)
{
throw new ArgumentException(SR.Format(SR.Arg_EnumValueNotFound, value.ToString()));
throw new ArgumentException(SR.Format(SR.Arg_EnumValueNotFound, originalValue.ToString()));
}

result = 0;
Expand Down
9 changes: 9 additions & 0 deletions src/libraries/System.Runtime/tests/System/EnumTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ private static void Parse_Generic_Invalid<T>(Type enumType, string value, bool i
}
}

[Theory]
[InlineData("Yellow")]
[InlineData("Yellow,Orange")]
public static void Parse_NonExistentValue_IncludedInErrorMessage(string value)
{
ArgumentException e = Assert.Throws<ArgumentException>(() => Enum.Parse(typeof(SimpleEnum), value));
Assert.Contains(value, e.Message);
}

[Theory]
[InlineData(SByteEnum.Min, "Min")]
[InlineData(SByteEnum.One, "One")]
Expand Down