我收到以下异常:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 未处理的异常呈现组件:“DefaultProxyCache
1' threw an exception. System.TypeInitializationException: The type initializer for 'DefaultProxyCache
1”的类型初始化程序引发异常。---> System.ArgumentException:无效的通用参数参数名称:typeArguments at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.MakeGenericMethod_impl(System.Reflection.RuntimeMethodInfo,System.Type[]) at System.Reflection.RuntimeMethodInfo .MakeGenericMethod(System.Type[] methodInstantiation) <0x342def8 + 0x000d6> in :0 at ProtoBuf.Grpc.Internal.ContractOperation.TryGetClientHelper() [0x0001b] in //src/protobuf-net.Grpc/Internal/ContractOperation.cs: 291 在 ProtoBuf.Grpc.Internal.ProxyEmitter.EmitFactory[TService] (ProtoBuf.Grpc.Configuration.BinderConfiguration binderConfig) [0x00477] 在 //src/protobuf-net.Grpc/Internal/ProxyEmitter.cs:238 在 ProtoBuf.Grpc.Internal.ProxyEmitter.CreateFactory[TService] (ProtoBuf.Grpc.Configuration.BinderConfiguration binderConfig) [0x0006d] in //src/protobuf-net .Grpc/Internal/ProxyEmitter.cs:123 at ProtoBuf.Grpc.Configuration.ClientFactory+DefaultProxyCache`1[TService]..cctor()[0x00000] in //src/protobuf-net.Grpc/Configuration/ClientFactory.cs: 81
我的项目使用 gRPC-Web、Blazor Web 程序集和 protobuf-net
这是我的服务合同:
[ServiceContract(Name = "Services.Customer")]
public interface ICustomerService
{
ValueTask<Customer> CreateCustomer(Customer customerDTO);
ValueTask<CustomerResultSet> GetCustomers();
}
实现是:
public class CustomerService : ICustomerService
{
private readonly CustomerUseCases customerLogic;
public CustomerService(CustomerUseCases customerLogic)
{
this.customerLogic = customerLogic;
}
public async ValueTask<Customer> CreateCustomer(Customer customerDTO)
{
var result = await customerLogic.CreateCustomer(customerDTO);
return customerDTO;
}
public async ValueTask<CustomerResultSet> GetCustomers()
{
CustomerResultSet result = new CustomerResultSet { Customers = await customerLogic.GetCustomer() };
return result;
}
}
至于数据合同:
[DataContract]
public class CustomerResultSet
{
[DataMember(Order = 1)]
public IEnumerable<Customer> Customers { get; set; }
}
和,
[DataContract]
public partial class Customer
{
[DataMember(Order = 1)]
public int CustomerId { get; set; }
[DataMember(Order = 2)]
public string CustomerName { get; set; }
}
在我返回服务中的客户列表之前,但我意识到我需要一个类来对消息进行建模,以便 protobuf-net 能够序列化,这就是 CustomerResultSet 的原因。尽管如此,它仍然无法正常工作。非常感谢任何帮助