Skip to content

Commit 397279b

Browse files
author
Johnny Pham
authored
Avoid throwing exception when receiving invalid SqlNotificationInfo value (#1378)
1 parent d853ac4 commit 397279b

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyListener.cs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,37 +1131,25 @@ internal static SqlNotification ProcessMessage(SqlXml xmlMessage)
11311131
messageAttributes |= MessageAttributes.Source;
11321132
break;
11331133
case InfoAttribute:
1134-
try
1135-
{
1136-
string value = xmlReader.Value;
1137-
// 3 of the server info values do not match client values - map.
1138-
switch (value)
1139-
{
1140-
case "set options":
1141-
info = SqlNotificationInfo.Options;
1142-
break;
1143-
case "previous invalid":
1144-
info = SqlNotificationInfo.PreviousFire;
1145-
break;
1146-
case "query template limit":
1147-
info = SqlNotificationInfo.TemplateLimit;
1148-
break;
1149-
default:
1150-
SqlNotificationInfo temp = (SqlNotificationInfo)Enum.Parse(typeof(SqlNotificationInfo), value, true);
1151-
if (Enum.IsDefined(typeof(SqlNotificationInfo), temp))
1152-
{
1153-
info = temp;
1154-
}
1155-
break;
1156-
}
1157-
}
1158-
catch (Exception e)
1134+
string value = xmlReader.Value;
1135+
// 3 of the server info values do not match client values - map.
1136+
switch (value)
11591137
{
1160-
if (!ADP.IsCatchableExceptionType(e))
1161-
{
1162-
throw;
1163-
}
1164-
ADP.TraceExceptionWithoutRethrow(e); // Discard failure, if it should occur.
1138+
case "set options":
1139+
info = SqlNotificationInfo.Options;
1140+
break;
1141+
case "previous invalid":
1142+
info = SqlNotificationInfo.PreviousFire;
1143+
break;
1144+
case "query template limit":
1145+
info = SqlNotificationInfo.TemplateLimit;
1146+
break;
1147+
default:
1148+
if (Enum.TryParse(value, true, out SqlNotificationInfo temp) && Enum.IsDefined(typeof(SqlNotificationInfo), temp))
1149+
{
1150+
info = temp;
1151+
}
1152+
break;
11651153
}
11661154
messageAttributes |= MessageAttributes.Info;
11671155
break;

0 commit comments

Comments
 (0)