"Dim client As New RestSharp.RestClient" not working

434 Views Asked by At

I have a VB.Net ClassLibrary project in VS 2019 and .Net Framework 3.5. The project has a reference to RestSharp. I then reference my class library project in a Windows Forms Application .NET Framework 3.5 app.

In the library, I have this code:

Dim client As New RestSharp.RestClient With {.BaseUrl = New Uri(IQProURL + "api/vault/" + id)}

does not throw an error, but also the below code with client is not able to generate a response:

Dim response = client.Execute(request)

However, if I reference my same class library using a Windows Application with .NET Core 3.1, everything works fine.

I am expecting a Json object as the response. I need to use this with the .NET Framework 3.5 app. How can I do this?

2

There are 2 best solutions below

1
Alexey Zimarev On

.NET Framework 3.5 reached the end of life a long time ago, and it's no longer supported by RestSharp. You need to visit NuGet.org and find the version of RestSharp that is compatible with .NET Framework 3.5. You need to be aware that neither .NET Framework 3.5, nor old versions of RestSharp receive any security patches or any other fixes.

3
RichG On

Thank you for that info about Fw 3.5 I was able to change the ClassLibrary to Fw 4.5 and the Windows Forms Application to Fw 4.5. I did find a combination of RestSharp and NewtonSoft.Json to work with Fw 4.5.
Under this configuration, on the dev computer the Windows Forms Application was able to dim a RestSharp client and a RestSharp responce all the way through deserializeing the Json object. That was a great thing to see. The Windows Forms Application will not run on XP now but I'm just going to tell the users to run it on Win10 or better and forget XP on this option. Next I ran the Windows Forms Application on a Win10 system by accessing it on dev computer in WindowsApp1\bin\Release the through the LAN. It did run, BUT it displayed the same inability to get RestSharp to dim a client.
These are the files in the WindowsApp1\bin\Release directory.

 - ClassLibrary1.dll 
 - ClassLibrary1.pdb 
 - ClassLibrary1.xml
 - Newtonsoft.Json.dll 
 - Newtonsoft.Json.xml 
 - RestSharp.dll 
 - RestSharp.xml
 - WindowsApp1.exe 
 - WindowsApp1.exe.config 
 - WindowsApp1.pdb
 - WindowsApp1.xml

Do I need to move some to the Win10 test system and register some of them?

This is my first VS application and I'm finding it to be very complicated as compared to VB6, but such is progress I guess.

I really appreciate any advise or wisdom or help here.