Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

x# VFP with Net Core 6 web api access 13 Dec 2022 19:04 #24756

  • spittenger
  • spittenger's Avatar
  • Topic Author


  • Posts: 3
  • 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).

    Please Log in or Create an account to join the conversation.

    x# VFP with Net Core 6 web api access 13 Dec 2022 20:18 #24761

    • robert
    • robert's Avatar


  • Posts: 3600
  • 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:
    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

    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:
    NotSupportedException: No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

    Robert

    One more thing:
    You will have to specify the path to the DBF as a FULL path.
    This will not work
    SET DEFAULT TO Data
    but this will work
    SET DEFAULT TO c:\TestProjects\VFPSampleCode\Data

    This is because the web app does not really have a "current directory".
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    x# VFP with Net Core 6 web api access 13 Dec 2022 21:53 #24762

    • spittenger
    • spittenger's Avatar
    • Topic Author


  • Posts: 3
  • Thanks Robert! that got me moving again.

    Please Log in or Create an account to join the conversation.

    x# VFP with Net Core 6 web api access 13 Dec 2022 22:05 #24763

    • spittenger
    • spittenger's Avatar
    • Topic Author


  • Posts: 3
  • 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:\VFF2022\MyData 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:\VFF2022\MyData\Customer.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.

    Please Log in or Create an account to join the conversation.

    Last edit: by spittenger. Reason: adding info

    x# VFP with Net Core 6 web api access 13 Dec 2022 23:08 #24766

    • robert
    • robert's Avatar


  • Posts: 3600
  • 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
    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

    And call that code in your startup code:
    InitRuntime.Start();

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1