Skip to content

Commit 87ef872

Browse files
Treat null/missing CmpContext and IsMasterPage as equivalent in GetGxObject
HttpAjaxContext.GetGxObject(JArray, CmpContext, IsMasterPage) iterates the array looking for an entry that matches the (CmpContext, IsMasterPage) pair. The previous lookup called obj['CmpContext'].ToString() and obj['IsMasterPage'].ToString() directly — when the array entry didn't carry those keys, the indexer returned null and ToString() threw NullReferenceException, which fell into the catch and made the function return null, breaking the callers (ajax_rsp_assign_attri and similar). Make the comparison null-safe and treat 'missing/null/empty' as semantically equivalent to the default value: - CmpContext: a missing/empty entry matches a null-or-empty parameter. - IsMasterPage: a missing/empty entry matches IsMasterPage == false (default for bool). Comparison is case-insensitive against IsMasterPage.ToString(). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 21dde5b commit 87ef872

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

dotnet/src/dotnetframework/GxClasses/Core/Web/HttpAjaxContext.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,17 @@ private JObject GetGxObject(JArray array, String CmpContext, bool IsMasterPage)
286286
for (int i = 0; i < array.Count; i++)
287287
{
288288
obj = array.GetObject(i);
289-
if (obj["CmpContext"].ToString().Equals(CmpContext) && obj["IsMasterPage"].ToString().Equals(IsMasterPage.ToString()))
289+
string objCmpContext = obj["CmpContext"]?.ToString();
290+
string objIsMasterPage = obj["IsMasterPage"]?.ToString();
291+
// A missing/null/empty CmpContext on the array entry is equivalent to a null-or-empty parameter.
292+
bool cmpContextMatches = string.IsNullOrEmpty(objCmpContext)
293+
? string.IsNullOrEmpty(CmpContext)
294+
: objCmpContext.Equals(CmpContext);
295+
// A missing IsMasterPage on the array entry is treated as the default value (false).
296+
bool isMasterPageMatches = string.IsNullOrEmpty(objIsMasterPage)
297+
? !IsMasterPage
298+
: objIsMasterPage.Equals(IsMasterPage.ToString(), StringComparison.OrdinalIgnoreCase);
299+
if (cmpContextMatches && isMasterPageMatches)
290300
{
291301
return obj;
292302
}
@@ -303,7 +313,7 @@ private JObject GetGxObject(JArray array, String CmpContext, bool IsMasterPage)
303313
}
304314

305315
return null;
306-
}
316+
}
307317

308318
public void ajax_rsp_assign_attri(String CmpContext, bool IsMasterPage, String AttName, Object AttValue)
309319
{

0 commit comments

Comments
 (0)