Skip to content

Commit a99102d

Browse files
[Storage] Fix NullReferenceException when parsing error response (Azure#48268)
1 parent 0bb2854 commit a99102d

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

sdk/storage/Azure.Storage.Common/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
- Fixed bug where in rare cases, a `NullReferenceException` could be thrown when parsing an error response from the service.
1011

1112
### Other Changes
1213

sdk/storage/Azure.Storage.Common/src/Shared/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ internal static class Constants
105105
public const string TrueName = "true";
106106

107107
public const string ErrorCode = "Code";
108+
public const string ErrorCodeLower = "code";
108109
public const string ErrorMessage = "Message";
110+
public const string ErrorMessageLower = "message";
109111

110112
public const string CommaString = ",";
111113
public const char CommaChar = ',';

sdk/storage/Azure.Storage.Common/src/Shared/StorageRequestFailedDetailsParser.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ public override bool TryParse(Response response, out ResponseError? error, out I
2727
if (response.Headers.ContentType.Contains(Constants.ContentTypeApplicationXml))
2828
{
2929
XDocument xml = XDocument.Load(contentStream);
30-
var errorCode = xml.Root!.Element(Constants.ErrorCode)!.Value;
31-
var message = xml.Root.Element(Constants.ErrorMessage)!.Value;
32-
data = new Dictionary<string, string>();
30+
var errorCode = xml.Root!.Element(Constants.ErrorCode)?.Value ??
31+
xml.Root.Element(Constants.ErrorCodeLower)?.Value;
32+
var message = xml.Root.Element(Constants.ErrorMessage)?.Value ??
33+
xml.Root.Element(Constants.ErrorMessageLower)?.Value;
3334

35+
data = new Dictionary<string, string>();
3436
foreach (XElement element in xml.Root.Elements())
3537
{
3638
switch (element.Name.LocalName)

0 commit comments

Comments
 (0)