gpt4 book ai didi

asp.net-core - 使用 gRPC-Web 和 protobuf-net 在工作服务中添加新方法时出现异常

转载 作者:行者123 更新时间:2023-12-03 19:09:16 26 4
gpt4 key购买 nike

我收到以下异常:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]Unhandled exception rendering component: The type initializer for 'DefaultProxyCache1' threw an exception. System.TypeInitializationException: The type initializer for 'DefaultProxyCache1' threw an exception. ---> System.ArgumentException: Invalid generic argumentsParameter name: typeArgumentsat (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 :0at ProtoBuf.Grpc.Internal.ContractOperation.TryGetClientHelper () [0x0001b] in //src/protobuf-net.Grpc/Internal/ContractOperation.cs:291at ProtoBuf.Grpc.Internal.ProxyEmitter.EmitFactory[TService] (ProtoBuf.Grpc.Configuration.BinderConfiguration binderConfig) [0x00477] in //src/protobuf-net.Grpc/Internal/ProxyEmitter.cs:238at ProtoBuf.Grpc.Internal.ProxyEmitter.CreateFactory[TService] (ProtoBuf.Grpc.Configuration.BinderConfiguration binderConfig) [0x0006d] in //src/protobuf-net.Grpc/Internal/ProxyEmitter.cs:123at ProtoBuf.Grpc.Configuration.ClientFactory+DefaultProxyCache`1[TService]..cctor () [0x00000] in //src/protobuf-net.Grpc/Configuration/ClientFactory.cs:81


我的项目使用 gRPC-Web、Blazor Web 程序集和 protobuf-net
这是我的服务契约(Contract):
[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;
}
}
至于数据契约(Contract):
[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 的原因。尽管如此,它还是行不通。
非常感谢任何帮助

最佳答案

那是……奇怪。 I can't repro it here ,所以我猜它是 Blazor 特有的。我已经检查了代码在“常规”框架中的作用,至少对我来说它似乎做了正确的事情 - 使用 UnaryValueTaskAsync<Customer, Customer>()UnaryValueTaskAsync<Empty, CustomerResultSet>() ,这正是我所期望的。我改进了该代码路径中的异常处理,至少让我们知道它正在尝试做什么,所以我的建议是:

  • 更新至 protobuf-net.Grpc版本 >= 1.0.119(我会在 CI 完成后立即部署它)
  • 重试,让我知道它现在说的是什么

  • 或者,如果您有一个包含 blazor 位的最小副本,例如 GitHub 存储库,我可以很高兴地查看那里。
    (提示:我尝试同时关注 Stack Overflow 和 GitHub,但 GitHub 可能更适合此类问题 - 我很高兴地说这是一个错误,所以: https://github.com/protobuf-net/protobuf-net.Grpc/issues)

    关于asp.net-core - 使用 gRPC-Web 和 protobuf-net 在工作服务中添加新方法时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62732593/

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