Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No marshaller available for xxx #306

Open
Roy-se7en opened this issue Aug 17, 2023 · 14 comments
Open

No marshaller available for xxx #306

Roy-se7en opened this issue Aug 17, 2023 · 14 comments

Comments

@Roy-se7en
Copy link

/// <summary>
/// 订单服务
/// </summary>
[ServiceContract(ConfigurationName = MicroServiceNames.ServOrders)]
public interface IOrderService
{
    /// <summary>
    /// 获取订单信息
    /// </summary>
    /// <param name="request"></param>
    /// <param name="context"></param>
    /// <returns></returns>
    [NonAction]
    Task<OrderDto> GetOrderByIdAsync(ProtoLong request, CallContext context = default);
}

(1).if only it as client , it work well.

    context.services.AddCodeFirstGrpcClient<T>(o =>
        {})

    .......

(2).now, it as client and server, and add grpc reflection

    context.Services.AddCodeFirstGrpc(options =>
    {
        options.EnableDetailedErrors = true;
    });
    context.Services.AddCodeFirstGrpcReflection();
    context.services.AddCodeFirstGrpcClient<T>(o =>
        {})

....

    app.UseMyGrpcServices();
    app.MapCodeFirstGrpcReflectionService();

now .i ocur the error :
---> System.TypeInitializationException: The type initializer for 'DefaultProxyCache`1' threw an exception.
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidOperationException: No marshaller available for Xchain.Share.Serv.Orders.Orders.OrderDto
at ProtoBuf.Grpc.Internal.MarshallerCache.g__Throw|5_0T in /_/src/protobuf-net.Grpc/Internal/MarshallerCache.cs:line 39

@mgravell
Copy link
Member

  1. which method is it that is throwing?
  2. can we see an approximation of OrderDto? (so I can assess what I would expect it to do)

@Roy-se7en
Copy link
Author

Roy-se7en commented Aug 18, 2023

if I don't use below code, it work well

context.Services.AddCodeFirstGrpcReflection();
...
app.MapCodeFirstGrpcReflectionService();

@Roy-se7en
Copy link
Author

/// <summary>
/// 列表项
/// </summary>
[ProtoContract]
public class OrderDto : OrderOutData
{
    /// <summary>
    /// 交期
    /// </summary>
    [ProtoMember(1)]
    public decimal? ProduceCycle { get; set; }

    /// <summary>
    /// 交易货币
    /// </summary>
    [ProtoMember(2)]
    public string Currency { get; set; }

    /// <summary>
    /// 交易货币汇率
    /// </summary>
    [ProtoMember(3)]
    public decimal ExchangeRate { get; set; }
    
    ...
}

 /// <summary>
/// 基础信息
/// </summary>
[ProtoContract]
[ProtoInclude(200, typeof(OrderDto))]
public class OrderOutData
{
    /// <summary>
    /// 询盘/订单Id
    /// </summary>
    [ProtoMember(1)]
    public long Id { get; set; }

    /// <summary>
    /// 客户id
    /// </summary>
    [ProtoMember(2)]
    public long MemberId { get; set; }

    /// <summary>
    /// 合伙人组织Id
    /// </summary>
    [ProtoMember(3)]
    public long CopartnerOrgId { get; set; }

    ...
}

@markushaslinger
Copy link

I ran into the same (or a similar) issue literally 20 minutes ago.

This fails:

[ServiceContract]
public interface IFooService
{
    [OperationContract]
    public ValueTask<FooResponse> Foo(FooRequest req);

    // other methods
}

[ProtoContract]
public sealed class FooResponse
{
    [ProtoMember(1)]
    public bool Exists { get; set; }

    [ProtoMember(2)]
    public LocalDate? PlanningStart { get; set; }

    [ProtoMember(3)]
    public LocalDate? PlanningEnd { get; set; }
}

with the following error:

System.InvalidOperationException: No marshaller available for Initech.Shared.Contract.Endpoints.FooResponse
   at ProtoBuf.Grpc.Internal.MarshallerCache.<GetMarshaller>g__Throw|5_0[T]() in /_/src/protobuf-net.Grpc/Internal/MarshallerCache.cs:line 39
   at ProtoBuf.Grpc.Internal.MarshallerCache.GetMarshaller[T]() in /_/src/protobuf-net.Grpc/Internal/MarshallerCache.cs:line 36
   at ProtoBuf.Grpc.Configuration.ServerBinder.AddMethod[TService,TRequest,TResponse](String serviceName, String operationName, MethodInfo method, MethodType methodType, ServiceBindContext bindContext, Func`3 invoker, MarshallerCache marshallerCache, ConstantExpression service, Boolean simplfiedExceptionHandling) in /_/src/protobuf-net.Grpc/Configuration/ServerBinder.cs:line 251
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithManyArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

Yet this works:

[ServiceContract]
public interface IFooService
{
    [OperationContract]
    public ValueTask<Bar> Foo(FooRequest req);

    // other methods
}

[ProtoContract]
public sealed class Bar
{
    [ProtoMember(1)]
    public required FooResponse Baz {get; set;}
}

[ProtoContract]
public sealed class FooResponse
{
    [ProtoMember(1)]
    public bool Exists { get; set; }

    [ProtoMember(2)]
    public LocalDate? PlanningStart { get; set; }

    [ProtoMember(3)]
    public LocalDate? PlanningEnd { get; set; }
}

I had another issue yesterday where simply wrapping an object made an issue go away, which I can't explain.

@mgravell
Copy link
Member

OK, that's weird; I'll investigate

@markushaslinger
Copy link

OK, that's weird; I'll investigate

Thanks a lot!
If it helps I could probably send you the contract DLL and the server setup code, but I can't post it somewere public so I'd need some e-mail or other way to send it.

@mgravell
Copy link
Member

I'm available at marc.gravell at gmail.com, or another way that often works is inviting @mgravell to a private github repo

@Roy-se7en
Copy link
Author

Roy-se7en commented Aug 18, 2023

<PackageReference Include="Google.Protobuf" Version="3.22.0" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.54.0" />
<PackageReference Include="Grpc.Tools" Version="2.54.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="protobuf-net.Grpc" Version="1.1.1" />

if i add the package as below,it occur the error that i given

<PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" Version="1.1.1" />
<PackageReference Include="System.ServiceModel.Primitives" Version="6.0.0" /> 

Is there any conflict ?

@markushaslinger
Copy link

I'm available at marc.gravell at gmail.com, or another way that often works is inviting @mgravell to a private github repo

You got mail. And because I forgot to mention it in the mail:

  • The object from the SO issue was MonthDto (now wrapped in UpdateMonthPlanRequest)
  • The object which leads to the marshaller error is MonthPlanExistsResponse

if i add the package as below,it occur the error that i given

I have the System.ServiceModel.Primitives because it is required for OperationContract, but I do not use protobuf-net.Grpc.AspNetCore.Reflection.

@Roy-se7en
Copy link
Author

I'm available at marc.gravell at gmail.com, or another way that often works is inviting @mgravell to a private github repo

You got mail. And because I forgot to mention it in the mail:

  • The object from the SO issue was MonthDto (now wrapped in UpdateMonthPlanRequest)
  • The object which leads to the marshaller error is MonthPlanExistsResponse

if i add the package as below,it occur the error that i given

I have the System.ServiceModel.Primitives because it is required for OperationContract, but I do not use protobuf-net.Grpc.AspNetCore.Reflection.

hello, have you find the problem?

@mgravell
Copy link
Member

If I had an update for you: I would have replied already. I haven't even had chance to look yet. Please be realistic about your expectations and demands here - this isn't paid commercial support; this is somebody giving up their free time to try to help strangers. I spent my weekend with my family. This is not my paid day job, and you're not a paying customer. Please don't pester people who are helping you on those terms! I'll look as soon as I can, but: don't nag - that just sucks the life and joy out of OSS.

@Roy-se7en
Copy link
Author

If I had an update for you: I would have replied already. I haven't even had chance to look yet. Please be realistic about your expectations and demands here - this isn't paid commercial support; this is somebody giving up their free time to try to help strangers. I spent my weekend with my family. This is not my paid day job, and you're not a paying customer. Please don't pester people who are helping you on those terms! I'll look as soon as I can, but: don't nag - that just sucks the life and joy out of OSS.

i'm sorry to disturb you, i neglect the time zone (it is workday in my zone).

@bizzare-bread
Copy link

I had the issue like this once. For me the reason was in my grpc model. I had a property which is an enum that was inside the library (nuget), and the library was not directly (implicitly) added as a dependency to the assembly where I had my grpc model. Hope this can help someone.

@DxsSucuk
Copy link

Is there any further Investigation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants