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

OperationDescriptorBuilder does not contain ctor with 2 parameters Linux-Docker #307

Open
aria321 opened this issue Jan 7, 2025 · 3 comments
Assignees

Comments

@aria321
Copy link

aria321 commented Jan 7, 2025

Describe the bug
Using last versionas 1.11.1 and the exception is throwing in Linux-Docker as:

Unhandled exception rendering component: OperationDescriptorBuilder does not contain ctor with 2 parameters. System.ArgumentException: OperationDescriptorBuilder does not contain ctor with 2 parameters. at ServiceModel.Grpc.Emit.ReflectionTools.Constructor(Type type, Int32 parametersCount) at ServiceModel.Grpc.Emit.CodeGenerators.ReflectDescriptor..ctor() at ServiceModel.Grpc.Emit.CodeGenerators.EmitContractBuilder.Build(ModuleBuilder moduleBuilder, ContractDescription1 description, String className) at ServiceModel.Grpc.Emit.EmitGenerator.GenerateContract(Type serviceType, ILogger logger) at ServiceModel.Grpc.Emit.EmitGenerator.GenerateClientBuilder[ITestService](ILogger logger) at ServiceModel.Grpc.Client.ClientRegistration.EmitBuilder[ITestService](ILogger ) at ServiceModel.Grpc.Client.ClientRegistration.Build[ITestService](IClientBuilder1 , ServiceModelGrpcClientOptions , Action1 ) at ServiceModel.Grpc.Client.ClientFactory.RegisterClient[ITestService](IClientBuilder1 , Action1 , Boolean ) at ServiceModel.Grpc.Client.ClientFactory.CreateClient[ITestService](CallInvoker ) at ServiceModel.Grpc.Client.ClientFactory.CreateClient[ITestService](ChannelBase ) at ServiceModel.Grpc.Client.GrpcClientExtensions.<>c__01[[Server.ITestService, Server.Infra, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]].b__0_0(IServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite , RuntimeResolverContext ) at

To Reproduce
I did some investigation and set log in public static ConstructorInfo Constructor(this Type type, int parametersCount) like below:

public static ConstructorInfo Constructor(this Type type, int parametersCount)
{
    var constructors = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
    Console.WriteLine($"==> Creating {type.Name}, Found Ctor Length:{constructors.Length}, Expected Params Count:{parametersCount}");
    ....
}

and see ==> Creating OperationDescriptorBuilder Found Ctor Length:0, Expected Params Count:2

Expected behavior
Supposed that ReflectDescriptor can create the ctor of OperationDescriptorBuilder by reflection, everything working well on Development Env and Windows Docker Desktop whether Linux or Windows Mode, but in Linux Docker OS above mentioned Exception is throwing, we had to downgrade to version 1.8

Environment

  • OS: Linux Docker
  • .Net 8

Additional context
Why var constructors = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) can not create or find a ctor with two parameters of OperationDescriptorBuilder which is exist and implemented.

@max-ieremenko
Copy link
Owner

Thank you for the bug report.

Unhandled exception rendering component: OperationDescriptorBuilder does not contain ctor with 2 parameters

It seems that ctor was removed by trimming.

Blazor WebAssembly performs IL trimming to reduce the size of the published output. Trimming occurs when publishing an app.

Consider switching to source code generation by ServiceModel.Grpc.DesignTime in your project, see ServiceModel.Grpc client code generation, example.

@aria321
Copy link
Author

aria321 commented Jan 8, 2025

You are welcome,
So you mean there are two option as

1- As the triming link describe trimming config, if we disable PublishTrimmed like <PublishTrimmed>false</PublishTrimmed> then it should work properly.

2- Or instead using ServiceModel.Grpc.DesignTime

but I am still confused why published app is working well on Windows Docker but had problem in Linux OS Docker,
Anyway Trimming should have the same behavior in both cases.

@max-ieremenko
Copy link
Owner

but I am still confused why published app is working well on Windows Docker but had problem in Linux OS Docker

The issue was reproducible on windows and Linux: dotnet publish --configuration Release ServiceModel.Grpc/Examples/BlazorApp/Server

The fix was released in version 1.12.0.

FYI Examples/BlazorApp/Client is changed to use ServiceModel.Grpc.DesignTime to generate required code during build time.

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

2 participants