Signalr Uno平台WASM信号器反序列化问题

Signalr Uno平台WASM信号器反序列化问题,signalr,prism,json-deserialization,webassembly,uno-platform,Signalr,Prism,Json Deserialization,Webassembly,Uno Platform,我有一个信号服务和一个Uno平台WASM客户端(带Prism)。我想调用一个hub方法,它返回一个模型。问题是,我有两个相同的模型(属性、方法等),但客户机在调用hub方法时只能接收其中一个。对于另一个模型,反序列化时会引发异常 枢纽: 视图模型: using Microsoft.AspNetCore.SignalR.Client; using Prism.Commands; using ReservationManagement.SignalRInterface.Model; namespa

我有一个信号服务和一个Uno平台WASM客户端(带Prism)。我想调用一个hub方法,它返回一个模型。问题是,我有两个相同的模型(属性、方法等),但客户机在调用hub方法时只能接收其中一个。对于另一个模型,反序列化时会引发异常

枢纽:

视图模型:

using Microsoft.AspNetCore.SignalR.Client;
using Prism.Commands;
using ReservationManagement.SignalRInterface.Model;

namespace ReservationManagement.UnoPrism.ViewModels
{
    class TestViewModel: ViewModelBase
    {

        private HubConnection HubConnection { get; set; }

        public DelegateCommand Loaded { get; private set; }


        public LocationModel LocationModel
        {
            get => _locationModel;
            set { SetProperty(ref _locationModel, value); }
        }

        private LocationModel _locationModel;

        public TestModel TestModel
        {
            get => _testModel;
            set { SetProperty(ref _testModel, value); }
        }

        private TestModel _testModel;

        public TestViewModel()
        {
            Loaded = new DelegateCommand(LoadedExecute);
        }

        private async void LoadedExecute()
        {


            HubConnection = new HubConnectionBuilder()
                .WithUrl("http://localhost:5000/TestServiceHubAnyOrigin")
                .WithAutomaticReconnect()
                .Build();

            await HubConnection.StartAsync();

            LocationModel = await HubConnection.InvokeAsync<LocationModel>("LocationModel");
            TestModel = await HubConnection.InvokeAsync<TestModel>("TestModel");
        }
    }
}

使用Microsoft.AspNetCore.signal.Client;
使用Prism.命令;
使用ReservationManagement.SignalRInterface.Model;
命名空间ReservationManagement.UnoPrism.ViewModels
{
类TestViewModel:ViewModelBase
{
专用HubConnection HubConnection{get;set;}
已加载公共DelegateCommand{get;private set;}
公共位置模型位置模型
{
get=>\u locationModel;
set{SetProperty(ref _locationModel,value);}
}
私人选址模型(LocationModel);;
公共测试模型测试模型
{
get=>\u testModel;
set{SetProperty(ref _testModel,value);}
}
私有测试模型(TestModel);;
公共TestViewModel()
{
Loaded=新的DelegateCommand(LoadedExecute);
}
私有异步void LoadedExecute()
{
HubConnection=新的HubConnectionBuilder()
.WithUrl(“http://localhost:5000/TestServiceHubAnyOrigin")
.WithAutomaticReconnect()
.Build();
等待HubConnection.StartAsync();
LocationModel=Wait HubConnection.InvokeAsync(“LocationModel”);
TestModel=await HubConnection.InvokeAsync(“TestModel”);
}
}
}
对LocationModel的调用工作正常,并将其设置为服务返回的内容。调用TestModel会导致异常。如果我切换调用顺序(1.TestModel,2.LocationModel),TestModel调用仍然会引发异常

当我为Uwp构建时,一切都非常好

例外情况:

System.NotSupportedException:不支持反序列化没有无参数构造函数、单一参数化构造函数或带“JsonConstructorAttribute”注释的参数化构造函数的类型。键入“ReservationManagement.SignalPrinterface.Model.TestModel”。路径:$|行号:0 |字节位置行:1。-->System.NotSupportedException:不支持反序列化没有无参数构造函数、单一参数化构造函数或带“JsonConstructorAttribute”注释的参数化构造函数的类型。键入“ReservationManagement.SignalPrinterface.Model.TestModel”


我也尝试过这一点,正如异常所示,使用一个单一的参数化构造函数和一个带“JsonConstructorAttribute”注释的参数化构造函数,但仍然是同一个异常。

这是一个与IL链接器步骤相关的一般性问题,该步骤删除检测为未使用的成员,在某些情况下,使用反射时会出现错误

您需要在WebAssembly项目中的
LinkerConfig.xml
文件中添加链接器描述符来修复此问题,可能是在包含
ReservationManagement
命名空间的程序集中

您可以找到有关的其他文档

namespace ReservationManagement.SignalRInterface.Model
{
    public class TestModel
    {
        public string Name { get; set; }

        public override string ToString()
        {
            return Name;
        }
    }
}


namespace ReservationManagement.SignalRInterface.Model
{
    public class LocationModel
    {
        public string Name { get; set; }

        public override string ToString()
        {
            return Name;
        }
    }
}
using Microsoft.AspNetCore.SignalR.Client;
using Prism.Commands;
using ReservationManagement.SignalRInterface.Model;

namespace ReservationManagement.UnoPrism.ViewModels
{
    class TestViewModel: ViewModelBase
    {

        private HubConnection HubConnection { get; set; }

        public DelegateCommand Loaded { get; private set; }


        public LocationModel LocationModel
        {
            get => _locationModel;
            set { SetProperty(ref _locationModel, value); }
        }

        private LocationModel _locationModel;

        public TestModel TestModel
        {
            get => _testModel;
            set { SetProperty(ref _testModel, value); }
        }

        private TestModel _testModel;

        public TestViewModel()
        {
            Loaded = new DelegateCommand(LoadedExecute);
        }

        private async void LoadedExecute()
        {


            HubConnection = new HubConnectionBuilder()
                .WithUrl("http://localhost:5000/TestServiceHubAnyOrigin")
                .WithAutomaticReconnect()
                .Build();

            await HubConnection.StartAsync();

            LocationModel = await HubConnection.InvokeAsync<LocationModel>("LocationModel");
            TestModel = await HubConnection.InvokeAsync<TestModel>("TestModel");
        }
    }
}