gpt4 book ai didi

c# - ASP.Net Core 3.0 SignalR HubConnection.InvokeAsync 抛出 : The JSON property name for 'whatever' collides with another property

转载 作者:太空宇宙 更新时间:2023-11-03 20:48:21 27 4
gpt4 key购买 nike

我的应用程序中使用了以下通过 SignalR 连接进行通信的 DTO/POCO 类:

class Base {
public string Value { get; set; }
}
class Child : Base {
public new string Value { get; set; }
}

这在 ASP.Net Core 2.2 中运行良好。然而,我在迁移到 3.0 后遇到了以下异常:

 Error Message:
System.InvalidOperationException : The JSON property name for 'Biz4x.Frontend.Web.DTO.BoardRates.BoardTemplateWithRatesDTO.Template' collides with another property.
Stack Trace:
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerPropertyNameConflict(JsonClassInfo jsonClassInfo, JsonPropertyInfo jsonPropertyInfo)
at System.Text.Json.JsonClassInfo..ctor(Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializerOptions.GetOrAddClass(Type classType)
at System.Text.Json.WriteStackFrame.Initialize(Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.WriteCore(Utf8JsonWriter writer, PooledByteBufferWriter output, Object value, Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.WriteValueCore(Utf8JsonWriter writer, Object value, Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize(Utf8JsonWriter writer, Object value, Type inputType, JsonSerializerOptions options)
at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteArguments(Object[] arguments, Utf8JsonWriter writer)
at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteInvocationMessage(InvocationMessage message, Utf8JsonWriter writer)
at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteMessageCore(HubMessage message, IBufferWriter`1 stream)
at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteMessage(HubMessage message, IBufferWriter`1 output)
at Microsoft.AspNetCore.SignalR.Client.HubConnection.SendHubMessage(ConnectionState connectionState, HubMessage hubMessage, CancellationToken cancellationToken)
at Microsoft.AspNetCore.SignalR.Client.HubConnection.InvokeCore(ConnectionState connectionState, String methodName, InvocationRequest irq, Object[] args, String[] streams, CancellationToken cancellationToken)
at Microsoft.AspNetCore.SignalR.Client.HubConnection.InvokeCoreAsyncCore(String methodName, Type returnType, Object[] args, CancellationToken cancellationToken)
at System.Threading.Tasks.ForceAsyncAwaiter`1.GetResult()
at Microsoft.AspNetCore.SignalR.Client.HubConnection.InvokeCoreAsync(String methodName, Type returnType, Object[] args, CancellationToken cancellationToken)

感谢任何建议和见解。

最佳答案

ASP.NET Core 2.2 使用 Newtonsoft.Json,ASP.NET Core 3.0 使用 System.Text.Json

您可以安装Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson nuget包并将其添加到IServiceCollection以切换到Newtonsoft.Json

services.AddSignalR().AddNewtonsoftJsonProtocol();

关于c# - ASP.Net Core 3.0 SignalR HubConnection.InvokeAsync 抛出 : The JSON property name for 'whatever' collides with another property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58325107/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com