I am developing a .NET Core 3.1 Azure Function App in Visual Studio 2022. After upgrading to the latest version of RestSharp today, I'm getting the following exception when I try to instantiate a new RestClient:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. File name: 'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' at RestSharp.Serializers.Json.SystemTextJsonSerializer..ctor()
Here is the code I'm using to instantiate the client:
var clientOptions = new RestClientOptions
{
BaseUrl = new Uri("https://xxxxxxx.com"),
Timeout = 29000
};
_restClient = new RestClient(clientOptions);
The error occurs regardless of whether I pass in a ClientOptions
object to the constructor.
I have tried installing version 5.0.0.0 of System.Text.Json via Nuget, but to no avail. I have also removed other packages which might have a dependency on a different version of System.Text.Json - but this doesn't seem to work either.
I have tried cleaning my solution, deleting the obj and bin folders, closing and reopening Visual Studio, and even rebooting my machine. Still no go.
Any suggestions? I'm tearing my hair out.