mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Cannot load multiple gRPC definitions #667
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tuncancn on GitHub (Jan 31, 2025).
Originally assigned to: @StefH on GitHub.
It works fine if I add single greet.proto file definition. But if I split the proto file to 2 files, request.proto and greet.proto, the former has HelloRequest definition only.
I always get 404 error.
Stack Trace:
Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
Task`1.GetResultCore(Boolean waitCompletionNotification)
GrpcMockTest.MultipleProtoTest() line 83
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
--RpcException
@StefH commented on GitHub (Jan 31, 2025):
Can you please provide the complete code?
@tuncancn commented on GitHub (Jan 31, 2025):
Hi Stef, please see the souce code below.
Proto file, request.proto
Proto file, greet.proto
@StefH commented on GitHub (Jan 31, 2025):
What if you switch?
So
@tuncancn commented on GitHub (Feb 1, 2025):
Still not working, same error.
After I debugged into WireMock.Net source code, I can see it's trying to solve the request object type from first proto definition in ProtoBufMatcher.DecodeAsync(byte[]? input, bool throwException, CancellationToken cancellationToken). So I have to put the request definition in the front of the definition array.
Unfortunately, my response is not defined in the same proto as request object, ProtoBufUtils.GetProtoBufMessageWithHeaderAsync(...) tries to get the response type from the first proto definition again.
@StefH commented on GitHub (Feb 1, 2025):
@tuncancn
It's a bit more complicated, sorry for that.
1.
You need the main proto file as first item (
protoDefinitionText)2.
You need to add a comment to the request proto file, so that WireMock.Net knows how to resolve.
Can you try that?
@StefH commented on GitHub (Feb 1, 2025):
https://github.com/WireMock-Net/WireMock.Net/pull/1252
@tuncancn commented on GitHub (Feb 1, 2025):
It works!!! Thank you, Stef!
I have another question, how should I return an Any type in the response object.
For example, I split the response object to a new proto, changed the content like this.
Added a generic class for converting other types to Any.
When I response the object like this, I always get an exception "{"No serializer for type System.Object is available for model (default)"}", I'm not sure what value I should set to AnyData in the anonymous initializer.
Here is the json content in debug view:
And if I need to return repeated Any values, what should I do?
@StefH commented on GitHub (Feb 1, 2025):
Any
For any, the object/json should look like something like this:
See also:
https://github.com/StefH/ProtoBufJsonConverter/blob/main/test/ProtoBufJsonConverterTests/ConverterTests.cs#L741
Repeated
I don't have an example or test for that...
@tuncancn commented on GitHub (Feb 1, 2025):
Yeah, I tried to conver the anonymous class to the text in the sample.
But I don't know how to specify the type for my custom class Greet.Response.Transaction, not predefined Protobuf types.
@StefH commented on GitHub (Feb 1, 2025):
The ProtoBufJsonConverter does not support anything else "type.googleapis.com" yet... I need to check if I can add this logic.
@tuncancn commented on GitHub (Feb 3, 2025):
Thank you, Stef!