xsharp.eu • XSharp.Core.Functions.WorkDir() - call from CAVO app via a .NET wrapper DLL
Page 1 of 1

XSharp.Core.Functions.WorkDir() - call from CAVO app via a .NET wrapper DLL

Posted: Thu Oct 27, 2022 6:08 am
by Michal Rajnoha
Greetings XSharp developers.

While we are still in the process of migrating old CAVO 2.8 applications to X#, I got the idea to try to run ReportPro3 X# via a wrapper .NET library to avoid issues in CAVO->X# type mismatches.
If I call ReportPro3 X# via this wrapper from a tester .NET application, it works perfectly fine, but if I try to run it from a CAVO application, the XSharp.Core.Functions.WorkDir() function throws an "Object reference not set to an instance of an object." exception.

Code: Select all

Object reference not set to an instance of an object.

   at XSharp.Core.Functions.WorkDir()
   at ReportPro3_Designer.Functions.InitDBFEnvironment()
   at ReportPro3_Designer.Functions.ReportProInit()
I then tried to call just the XSharp.Core.Functions.WorkDir() function outside of ReportPro3 X# entirely and it produces the same exception.
So I'm thinking if there is some kind of property CAVO applications do not set in their application thread which the WorkDir() function requires, or am I missing something else?

XSharp.Core.Functions.WorkDir() - call from CAVO app via a .NET wrapper DLL

Posted: Thu Oct 27, 2022 6:12 am
by robert
Michal,
Are you calling the .Net app as a COM Object?
Maybe the runtime state is not properly initialized?
Can you create an example ?

Robert

XSharp.Core.Functions.WorkDir() - call from CAVO app via a .NET wrapper DLL

Posted: Thu Oct 27, 2022 6:23 am
by Michal Rajnoha
The wrapper is a .NET 4.7.2 library registered in COM via RegASM.exe, and the wrapper class is then instantiated in CAVO using OLEAutoObject.
I will try to put some minimalistic example together.

XSharp.Core.Functions.WorkDir() - call from CAVO app via a .NET wrapper DLL

Posted: Thu Oct 27, 2022 7:42 am
by Michal Rajnoha
robert post=24272 userid=253 wrote:Can you create an example ?
There are two projects in the attached file.
One is a Visual Studio 2015 solution with the wrapper library and a WPF tester application. Run it and press the button, it calls the mentioned function just fine and displays the working directory in a message box.
The other is a CAVO 2.8 SP3 project which calls the same wrapper library. Run it and press Open file. It gets the object reference error.
Don't forget to register the wrapper library, there is a BAT file included to do this.

XSharp.Core.Functions.WorkDir() - call from CAVO app via a .NET wrapper DLL

Posted: Thu Oct 27, 2022 1:07 pm
by robert
Michal,

Thanks for the example.
I see that you are using X# version 2.8a from May 2021.
This was fixed in a build after 2.8a (in October 2021).
If you use the latest build of X# this should work correctly.
The original code was using System.Reflection.Assembly.GetEntryAssembly() to fetch the main assembly.
In the case of a component running from COM this main assembly is not a .Net assembly so the call returns a NULL_OBJECT.
As alternative we now fall back to System.Reflection.Assembly.GetExecutingAssembly() which returns the location of the XSharp.Core.DLL.

Robert

XSharp.Core.Functions.WorkDir() - call from CAVO app via a .NET wrapper DLL

Posted: Thu Oct 27, 2022 1:11 pm
by Michal Rajnoha
Great, thanks, Robert. I will get the latest build then.