hor*_*eds 9 .net c# restsharp azure-functions
我在 Visual Studio 中有一个 C#(Azure 函数应用程序)项目。.Net 6.0
我将 RestSharp 更新到版本 110.2.0,现在出现此错误:
[2023-04-29T21:34:10.399Z] Executed 'RequestItemsPage' (Failed, Id=8eefbb7c-3bc0-44db-81e4-14c56096fc81, Duration=63ms)
[2023-04-29T21:34:10.401Z] System.Private.CoreLib: Exception while executing function: RequestItemsPage. System.Private.CoreLib: Exception has been thrown by the target of an invocation. RestSharp: Could not load file or assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
[2023-04-29T21:34:10.408Z] eb4802876b9e44839f63422be68619dc: Function 'RequestItemsPage (Activity)' failed with an error. Reason: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
[2023-04-29T21:34:10.411Z] ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
[2023-04-29T21:34:10.412Z] File name: 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
[2023-04-29T21:34:10.413Z] at RestSharp.Serializers.Json.SystemTextJsonSerializer..ctor()
[2023-04-29T21:34:10.423Z] at System.RuntimeType.CreateInstanceOfT()
[2023-04-29T21:34:10.423Z] --- End of inner exception stack trace ---
[2023-04-29T21:34:10.427Z] at System.RuntimeType.CreateInstanceOfT()
[2023-04-29T21:34:10.429Z] at System.Activator.CreateInstance[T]()
[2023-04-29T21:34:10.430Z] at RestSharp.Serializers.SerializerConfig.<>c__5`1.<UseSerializer>b__5_0()
[2023-04-29T21:34:10.434Z] at RestSharp.Serializers.SerializerConfig.UseSerializer(Func`1 serializerFactory)
[2023-04-29T21:34:10.438Z] at RestSharp.RestClient.ConfigureSerializers(ConfigureSerialization configureSerialization)
[2023-04-29T21:34:10.439Z] at RestSharp.RestClient..ctor(RestClientOptions options, ConfigureHeaders configureDefaultHeaders, ConfigureSerialization configureSerialization, Boolean useClientFactory)
[2023-04-29T21:34:10.444Z] at ContentHub_ItemUpdates.Producers.PullAllContentHubtemsByPage.RequestItemsPage(Int32 skip, ILogger log) in C:\Users\bwarrick\Workspace\.NET\Integrations_MDM\ContentHub_ItemUpdates\ContentHub_ItemUpdates\Producers\PullAllContentHubtemsByPage.cs:line 58
[2023-04-29T21:34:10.479Z] at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments)
[2023-04-29T21:34:10.480Z] at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 581
[2023-04-29T21:34:10.481Z] at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 527
[2023-04-29T21:34:10.499Z] at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 306. IsReplay: False. State: Failed. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.9.4. SequenceNumber: 7. TaskEventId: 0
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为此版本的 RestSharp 依赖于 System.Text.Json >= 7.0.2。我检查了依赖项,它就在那里——而且我在更新时也看到它正在升级 System.Text.Json。
我尝试安装 System.Text.Json 的 NuGet 包。没用。然后我尝试卸载并重新安装 RestSharp。打扫。重建。重新启动 Visual Studio。
我还尝试降级 Restsharp。我开始认为我破坏了我的项目并且需要废弃它......
对此有什么想法吗?
Ale*_*rev 23
我遇到了与问题相同的问题,该问题是由 Azure Functions 部署方法引起的,该方法删除了一些被认为“不必要”的程序集,因为它们可能包含在运行时中。
这里提供了正确的答案,基本上是向项目文件添加一个属性:
<PropertyGroup>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
Pra*_* KV -1
我创建了一个示例 Http Azure 函数来检查两个包的版本是否彼此兼容,如doc中所述。我看不出软件包及其版本有任何问题。
正如您所提到的,RestSharp 有 System.Text.Json 作为依赖项,如下所示:

RestSharp和System.Text.JsonDLL 进行检查,然后通过安装这些软件包的最新版本来重新添加它们,以确保没有冲突。尝试使用最新的预发布版本RestSharp 110.2.1-alpha.0.1。此版本还兼容System.Text.Json本文档中所示的内容。

如果这不起作用,请创建一个新项目并安装这两个软件包,如果问题仍然存在。
创建了一个示例项目并安装了 RestSharp 110.2.0 和 System.Text.Json 7.0.0 包,并观察到这两个包版本彼此兼容。

结果:

| 归档时间: |
|
| 查看次数: |
5555 次 |
| 最近记录: |