Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.Net Core 3.0 SignalR HubConnection.InvokeAsync抛出';不管怎样';与另一个属性冲突_C#_Asp.net Core_Json.net_Signalr - Fatal编程技术网

C# ASP.Net Core 3.0 SignalR HubConnection.InvokeAsync抛出';不管怎样';与另一个属性冲突

C# ASP.Net Core 3.0 SignalR HubConnection.InvokeAsync抛出';不管怎样';与另一个属性冲突,c#,asp.net-core,json.net,signalr,C#,Asp.net Core,Json.net,Signalr,我的应用程序中使用了以下DTO/POCO类,通过信号机连接进行通信: class Base { public string Value { get; set; } } class Child : Base { public new string Value { get; set; } } 这在ASP.NETCore2.2中运行良好。但是,在迁移到3.0后,我遇到了以下异常: Error Message: System.InvalidOperationExceptio

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

class Base {
     public string Value { get; set; }
}
class Child : Base {
     public new string Value { get; set; }
}
这在ASP.NETCore2.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

您可以安装nuget软件包并将其添加到
IServiceCollection
以切换到
Newtonsoft.Json

services.AddSignalR().AddNewtonsoftJsonProtocol();
public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddControllers().AddNewtonsoftJson()
    ...
}

如果要切换回使用Newtonsoft.Json的先前默认设置,请执行以下操作:

  • 安装Microsoft.AspNetCore.Mvc.NewtonsoftJsonNuGet软件包
  • ConfigureServices()
    中添加对
    AddNewtonsoftJson()的调用