x# VFP with Net Core 6 web api access
- spittenger
- Posts: 3
- Joined: Mon Oct 17, 2022 4:30 pm
x# VFP with Net Core 6 web api access
I am referring to the sample materials provided at the Fox Fest 2022. I have created a Visual Studio 2022 project including the forms project from the examples. In the example a form is displayed and when a button is clicked a query is run against a local customer.dbf. This returns a result set and works as expected. When I add an additional project that is net core 6 web api and call the method I can step into the foxpro code (same code called by the form) however I get an error proclaiming there is no instance of the object instantiated. The error occurs when executing the "use customer" line. My api controller can see the class just fine and I get no errors when compiling. It feels like I'm spinning my wheels on this and perhaps someone in the community has already figured this out. Any help is appreciated. I AM ATTACHING A SCREENSHOT OF THE ERROR AND THE VS PROJECT (IN 7Z FORMAT FOR SIZE).
- Attachments
-
- xSharp_test_project_VS_2022.png (114.1 KiB) Viewed 1888 times
-
- SampleCode.7z
- (3.01 MiB) Downloaded 163 times
x# VFP with Net Core 6 web api access
Steven,
The code in our RDD system detects that the RDD is encoded with code page 1252. That code page is not automatically available in .Net 6.
To make the codepage available include the following code in your Startup class constructor:
Because of the missing codepage, the DBF closes immediately.
Unfortunately there is a bug in the RDD code that tries to close an object that was not initialized at that moment.
As a result of that you see the error about the uninitialized object and not an error message about the codepage that is not available.
I have changed the RDD code in my local build and then the following error message is displayed in the browser:
Robert
One more thing:
You will have to specify the path to the DBF as a FULL path.
This will not work
but this will work
This is because the web app does not really have a "current directory".
The code in our RDD system detects that the RDD is encoded with code page 1252. That code page is not automatically available in .Net 6.
To make the codepage available include the following code in your Startup class constructor:
Code: Select all
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Unfortunately there is a bug in the RDD code that tries to close an object that was not initialized at that moment.
As a result of that you see the error about the uninitialized object and not an error message about the codepage that is not available.
I have changed the RDD code in my local build and then the following error message is displayed in the browser:
Code: Select all
NotSupportedException: No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
One more thing:
You will have to specify the path to the DBF as a FULL path.
This will not work
Code: Select all
SET DEFAULT TO Data
Code: Select all
SET DEFAULT TO c:TestProjectsVFPSampleCodeData
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
- spittenger
- Posts: 3
- Joined: Mon Oct 17, 2022 4:30 pm
x# VFP with Net Core 6 web api access
Thanks Robert! that got me moving again.
- spittenger
- Posts: 3
- Joined: Mon Oct 17, 2022 4:30 pm
x# VFP with Net Core 6 web api access
I modified my set default to point to a local directory that exists. I am using a table that has a dictionary file. I have in the folder C:VFF2022MyData a .DBC, .DCT, and a .DCX file for the dictionary and a .DBF, .CDX and .FPT for the customer table. I am getting a new exception: XSharp.RDD.RddError: 'Could not find file 'C:VFF2022MyDataCustomer.DBT'.' (noting free tables worked fine)
also noting that this may not be cause by a missing valid database container.
It appears to be looking for a file that isn't in that folder. Visual Foxpro doesn't seem to cry about it when using the customer table.
Any thoughts? Robert?
Thanks in advance.
also noting that this may not be cause by a missing valid database container.
It appears to be looking for a file that isn't in that folder. Visual Foxpro doesn't seem to cry about it when using the customer table.
Any thoughts? Robert?
Thanks in advance.
x# VFP with Net Core 6 web api access
The default RDD in X# is DBFNTX.
If you link XSharp.VFP AND you have an X# main program then the default RDD gets changed to the FoxPro compatible RDD because there is an Init procedure in XSharp.VFP that gets called from the main program.
However, your main program is Asp.Net. You will have to trigger the startup code that the compiler generates yourself. The easiest way to do so is by calling XSharpLoadLibrary(). That function takes care of everything.
Add the following to your X# library
And call that code in your startup code:
Robert
If you link XSharp.VFP AND you have an X# main program then the default RDD gets changed to the FoxPro compatible RDD because there is an Init procedure in XSharp.VFP that gets called from the main program.
However, your main program is Asp.Net. You will have to trigger the startup code that the compiler generates yourself. The easiest way to do so is by calling XSharpLoadLibrary(). That function takes care of everything.
Add the following to your X# library
Code: Select all
STATIC CLASS InitRuntime
STATIC METHOD Start() AS VOID STRICT
LOCAL cDir AS STRING
cDir := WorkDir()
XSharpLoadLibrary(cDir+"XSharp.Core.DLL")
XSharpLoadLibrary(cDir+"XSharp.RT.DLL")
XSharpLoadLibrary(cDir+"XSharp.VFP.DLL")
END CLASS
Code: Select all
InitRuntime.Start();
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu