我正在使用Visual Studio 2022开发一个.NET Core 3.1 Azure函数应用程序。今天我升级了RestSharp到最新版本后,当我尝试实例化一个新的RestClient时,出现了以下异常:
System.Reflection.TargetInvocationException: 调用目标的异常。 ---> System.IO.FileNotFoundException: 找不到文件或程序集'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'。系统无法找到指定的文件。 文件名:'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' at RestSharp.Serializers.Json.SystemTextJsonSerializer..ctor()
这是我用来实例化客户端的代码:
无论我是否向构造函数传递
System.Reflection.TargetInvocationException: 调用目标的异常。 ---> System.IO.FileNotFoundException: 找不到文件或程序集'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'。系统无法找到指定的文件。 文件名:'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' at RestSharp.Serializers.Json.SystemTextJsonSerializer..ctor()
这是我用来实例化客户端的代码:
var clientOptions = new RestClientOptions
{
BaseUrl = new Uri("https://xxxxxxx.com"),
Timeout = 29000
};
_restClient = new RestClient(clientOptions);
无论我是否向构造函数传递
ClientOptions 对象,都会出现错误。
我尝试通过Nuget安装System.Text.Json 5.0.0.0版本,但无济于事。我还删除了其他可能依赖不同版本的System.Text.Json的软件包,但似乎也不起作用。
我尝试清理解决方案,删除obj和bin文件夹,关闭并重新打开Visual Studio,甚至重新启动计算机。但仍然无法解决问题。
有什么建议吗?我都急疯了。
RestSharp.Serializers.SystemTextJson
。 - Lei YangMicrosoft.Azure.WebJobs.Extensions.*
和/或Microsoft.NET.Sdk.Functions
。我通过将我的测试VS项目转换为函数应用程序来验证了这一点。显然,最新版本的RestSharp与.NET Core 3.1函数应用程序不完全兼容。我将尝试恢复到早期版本的RestSharp和/或将我的函数应用程序更新到.NET 5或6。 - QBBryant