From 883f4bb9af176de8d2941da94cd3eeee002cb134 Mon Sep 17 00:00:00 2001 From: claudiamurialdo <33756655+claudiamurialdo@users.noreply.github.com> Date: Tue, 26 May 2026 10:11:40 -0300 Subject: [PATCH] Treat null/missing CmpContext and IsMasterPage as equivalent in GetGxObject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../GxClasses/Core/Web/HttpAjaxContext.cs | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Core/Web/HttpAjaxContext.cs b/dotnet/src/dotnetframework/GxClasses/Core/Web/HttpAjaxContext.cs index 44b0abb6a..268bef365 100644 --- a/dotnet/src/dotnetframework/GxClasses/Core/Web/HttpAjaxContext.cs +++ b/dotnet/src/dotnetframework/GxClasses/Core/Web/HttpAjaxContext.cs @@ -279,31 +279,38 @@ public void ajax_rspEndCmp() } private JObject GetGxObject(JArray array, String CmpContext, bool IsMasterPage) - { - try - { - JObject obj; + { + try + { + JObject obj; + string paramCmpContext = CmpContext ?? string.Empty; + string paramIsMasterPage = IsMasterPage.ToString(); + for (int i = 0; i < array.Count; i++) - { + { obj = array.GetObject(i); - if (obj["CmpContext"].ToString().Equals(CmpContext) && obj["IsMasterPage"].ToString().Equals(IsMasterPage.ToString())) - { - return obj; - } - } - obj = new JObject(); - obj.Put("CmpContext", CmpContext); - obj.Put("IsMasterPage", IsMasterPage.ToString()); + string objCmpContext = obj["CmpContext"]?.ToString() ?? string.Empty; + string objIsMasterPage = obj["IsMasterPage"]?.ToString() ?? string.Empty; + + if (objCmpContext.Equals(paramCmpContext) && objIsMasterPage.Equals(paramIsMasterPage)) + { + return obj; + } + } + + obj = new JObject(); + obj.Put("CmpContext", CmpContext); + obj.Put("IsMasterPage", IsMasterPage.ToString()); array.Add(obj); - return obj; - } + return obj; + } catch (Exception ex) { GXLogging.Error(log, "GetGxObject error", ex); } return null; - } + } public void ajax_rsp_assign_attri(String CmpContext, bool IsMasterPage, String AttName, Object AttValue) {