Results 1 to 2 of 2

Thread: ClassLibrary using RestSharp not working when called by VB5 program

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Atlanta, Georgia

    ClassLibrary using RestSharp not working when called by VB5 program

    Target system XP SP3. or Win 7 or Win 11. Legacy program written with VS VB5. ClassLibrary written using VS 2019 Target Framework .NET Framework 3.5. Using RestSharp.Net20 or RestSharp.Net2
    The following code works fine when the program calling GetCustomer is generated in VS2019 VB on the development system, but when the calling program is generated in VB5 a failure occurs. MsgBox is used to display the location of the pointer in the compiled and RegAsm dll from VS2019 when ran on XP. Rootobject is the structure the serialized return string is deserialized into. Since VB5 has no way to deserialize, and cannot seem to handler a 2,000 byte string coming back, the VB5 program makes multiple calls to get the data from the root structure.
    Dim client does return the URL so it seems to work ok. Dim request returns with RestSharp.RestRequest
    Dim response = client.Execute(request) seems to work ok as the responce becomes a RestSharp.RestResponce. So it is using RestSharp ok. I don't know if it actually reaches the API though.

    Imports RestSharp
    Imports Newtonsoft.Json
    <ComClass(CustomerTools.ClassId, CustomerTools.InterfaceId, CustomerTools.EventsId)>
    Public Class CustomerTools
    #Region "COM GUIDs"
        ' These  GUIDs provide the COM identity for this class 
        ' and its COM interfaces. If you change them, existing 
        ' clients will no longer be able to access the class.
        Public Const ClassId As String = "b3c660d0-4db3-498e-846e-4d93067176f3"
        Public Const InterfaceId As String = "12dd021d-228a-4f48-a75b-ff479634e810"
        Public Const EventsId As String = "3efef713-9086-435e-80ac-63a1e017f7eb"
    #End Region
        ' A creatable COM class must have a Public Sub New() 
        ' with no parameters, otherwise, the class will not be 
        ' registered in the COM registry and cannot be created 
        ' via CreateObject.
        Public Sub New()
        End Sub
        Public Function GetCustomer(id As String, setRoot As Boolean, Optional dataPiece As String = "")
            Static custRoot As Rootobject
            Dim x
            msgBoxSub(id & " " & setRoot)	'1
            If setRoot Then
                'set the customers data into custRoot
                'Clear the custRoot structure 
                custRoot = Nothing
                Dim client As New RestSharp.RestClient With {.BaseUrl = New Uri(IQProURL + "api/vault/" + id)}
                x = client.BaseUrl.ToString  	'returns the url with arguments
                msgBoxSub(x)	'2
                client.Timeout = -1
                Dim request As New RestRequest(Method.GET)
                request.AddHeader("Authorization", _apiKey)
                request.AddHeader("Content-Type", "application/json")
                x = request.ToString		'returns RestSharp.RestRequest
                msgBoxSub(x)	'3
                Dim response = client.Execute(request)
                x = response.ToString		'returns RestSharp.RestResponse
                msgBoxSub(x)   '4
                x = response.StatusCode.ToString   'returns 0
                msgBoxSub(x)    '5
                x = response.Content.ToString	'returns an empty string
                msgBoxSub(x)    '6
                x = response.ToString
                msgBoxSub(x)    '7
                'refrerence this .tlb in a VB5 program runnin on an XP system, this fails here
                x = response.Server.ToString	'Object reference not set to an instance of an object
                x = response.StatusDescription      'same faliure
                msgBoxSub(x)    '8
                Dim IQProresponse As Rootobject
                IQProresponse = JsonConvert.DeserializeObject(Of Rootobject)(response.Content)
                custRoot = IQProresponse
                x = response.Content
                x = IQProresponse.ToString
                If (response.StatusDescription = "OK") Then
                    Return True
                    Return False
                End If
                Return ParseRoot(custRoot, dataPiece)
            End If
        End Function
        Public Sub msgBoxSub(x)
            Static y = 1
            MsgBox(x & " " & y.ToString)
            y += 1
        End Sub
        Private Function ParseRoot(ByVal RootObj As Rootobject, dataPiece As String)
            Dim returnedData
            Select Case dataPiece
                Case "First_Name"
                    returnedData = RootObj.Data.Data.Customer.Addresses(1).First_name
                Case "do_not_share"
                    returnedData = RootObj.Data.Data.Customer.Do_not_share
    	    'all other cases go here
            End Select
            Return returnedData
        End Function
    End Class
    Last edited by GRichG; Aug 19th, 2022 at 05:06 PM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Atlanta, Georgia

    Re: ClassLibrary using RestSharp not working when called by VB5 program on

    After posting this I tried running the VB5 program on multiple computers using multiple versions of Windows. The failure was the same on all of them.
    I'm to move a VS 2019 version of the calling program to the test systems and see if that makes a difference....after the's Friday 6pm and I'm tired of messing with it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width