Skip to content

Commit 58ef1f4

Browse files
author
dalvarellos
committed
Refactor GxDynamicCall: fix props, improve assembly loading
Added missing using directives and a public AssemblyName constant. Fixed property setters for Properties and ExtendedProperties. Enhanced VerifyDefaultProperties to use the AssemblyName constant, improved cross-platform assembly loading logic, and added better exception handling for load failures. These changes improve correctness, maintainability, and compatibility.
1 parent c88b654 commit 58ef1f4

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Reflection;
45
using GeneXus.Application;
56
using GeneXus.Metadata;
67
using GeneXus.Utils;
8+
using GxClasses.Helpers;
79

810
namespace GeneXus.DynamicCall
911
{
1012
public class GxDynamicCall
1113
{
1214
private const string defaultMethod = "execute";
15+
public const string AssemblyName = "AssemblyName";
1316
private Assembly _assembly;
1417
private readonly IGxContext _context;
1518
private GXProperties _extendedProperties;
@@ -26,7 +29,7 @@ public GxDynCallProperties Properties
2629
get => _properties;
2730
set
2831
{
29-
_properties = Properties;
32+
_properties = value;
3033
}
3134
}
3235

@@ -35,7 +38,7 @@ public GXProperties ExtendedProperties
3538
get => _extendedProperties;
3639
set
3740
{
38-
_extendedProperties = ExtendedProperties;
41+
_extendedProperties = value;
3942
}
4043
}
4144
public GxDynamicCall()
@@ -58,24 +61,35 @@ private void VerifyDefaultProperties()
5861

5962
if (_assembly is null)
6063
{
61-
if (string.IsNullOrEmpty(_extendedProperties.Get("AssemblyName")))
64+
if (string.IsNullOrEmpty(_extendedProperties.Get(AssemblyName)))
6265
{
66+
#if NETCORE
67+
var stackTrace = new StackTrace();
68+
var frame = stackTrace.GetFrame(2);
69+
var method = frame.GetMethod();
70+
var assembly = method.DeclaringType.Assembly;
71+
_assembly = assembly;
72+
#else
6373
_assembly = Assembly.GetCallingAssembly();
74+
#endif
6475
}
6576
else
6677
{
6778
try
6879
{
69-
_assembly = Assembly.LoadFrom(_extendedProperties.Get("AssemblyName"));
80+
#if NETCORE
81+
_assembly = AssemblyLoader.LoadAssembly(new AssemblyName(_extendedProperties.Get(AssemblyName)));
82+
#else
83+
_assembly = Assembly.LoadFrom(_extendedProperties.Get(AssemblyName) + ".dll" );
84+
#endif
7085
}
71-
catch
86+
catch (Exception e)
7287
{
73-
throw;
88+
throw new InvalidOperationException("Error loading assembly: " + _extendedProperties.Get(AssemblyName), e);
7489
}
7590
}
7691
}
7792
}
78-
7993
public void Execute(ref IList<object> parameters, out IList<SdtMessages_Message> errors)
8094
{
8195
Create(null, out errors);

0 commit comments

Comments
 (0)