Ausnahme durch CLR oder externen Code ausgelöst – bei Reference zu ReportPro2

Deutschsprachiges X#-Forum – German language forum

Moderator: wriedmann

Post Reply
comitas2
Posts: 48
Joined: Thu Jul 18, 2019 9:13 am
Location: Germany

Ausnahme durch CLR oder externen Code ausgelöst – bei Reference zu ReportPro2

Post by comitas2 »

Hallo,
in meinem Hauptprogramm gibt es Indexdateien, die zur Laufzeit eine Funktion (z.B. CCHR() ) benötigen.
Da die gezeichneten Reporte vom ReportPro2 sich ebenfalls dieser Indexdateien bedienen müssen, muss über die ReportPro2_UDF diese Funktion auch bereitgestellt werden. Nun gibt es aber den unschönen Effekt, dass das Hauptprogramm mit einem Laufzeitfehler keinen Index erzeugt:

"Ausnahme durch CLR oder externen Code ausgelöst: Makrocompiler (1,13): Fehler XM0209: Mehrdeutiger Aufruf, könnte ReportPro2_UDF.Functions.CCHR(XSharp.__Usual[]) oder Hauptprogramm.Exe.Functions.CCHR(XSharp.__Usual[] sein)

Natürlich gibt es notwendigerweise diese Funktion zweimal: einmal in der Hauptprogramm.prg und in der Function.prg von ReportPro2.Udf. Im VO und Vulcan hatte das ohne Probleme funktioniert. Erst wenn ich die Funktion in ReportPro2.Udf umbenenne wird zwar im Hauptprogramm nun indiziert, aber den Reporten fehlt jetzt diese Funktion.
Hat jemand eine Idee, wie man das lösen kann?
Gruß Jörg
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Ausnahme durch CLR oder externen Code ausgelöst – bei Reference zu ReportPro2

Post by robert »

Jörg,

The X# macro compiler is a bit more sensitive to duplicate functions.
You can add a so called "macro resolver" to your code to aid the macro compiler to resolve duplicate function names.
This is not very easy, but doable.

To do so you need to create a function with the following prototype:


Code: Select all

USING System.Reflection


Function MyResolver( m1 AS MemberInfo, m2 AS MemberInfo,args AS Type[]) AS LONG
// decide which one to use and return either 1 or 2.
RETURN 1
This function needs to be registered with the runtime:

Code: Select all

SetMacroDuplicatesResolver(MyResolver)
Whenever the macro compiler does not know which function to choose it will call your function then.
Each of the MemberInfo objects will contain information about the functions found and the Type[] array contains the types of the arguments used in the code.
By returning 1 or 2 you can tell the macro compiler which one to choose.
Any other value will tell the macro compiler that you don't know.
From the MethodInfo you can find a property "DeclaringType" that returns the type where the function was created and from that type you can find the property "Assembly" that returns assembly where it was defined.
The DeclaringType will be a compiler generated Functions class. Something like MyDll.Functions

See https://docs.microsoft.com/en-us/dotnet ... mework-4.8
for more info about methodinfo and the classes that it inherits from.

The SetMacroDuplicatesResolver() function returns the previous value of the resolver.
You may want to save this value and check to see if this is null and when it is not, you may also want to call the old resolver when you don't know which one to choose.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
comitas2
Posts: 48
Joined: Thu Jul 18, 2019 9:13 am
Location: Germany

Ausnahme durch CLR oder externen Code ausgelöst – bei Reference zu ReportPro2

Post by comitas2 »

Hallo Robert,
Danke für die Erklärung. Da wäre ich ja im Leben nicht draufgekommen.
Mal sehen ob ich den Hinweis umsetzen kann ...
Jörg
Post Reply