I want to create a simple WPF Core, gRPC project. This "code" works perfectly in my .NET Core Console app, however WPF seems to be something special.
Proto File
syntax = "proto3";
option csharp_namespace = "MyProtoNamespace";
package greet;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply);
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings.
message HelloReply {
string message = 1;
}
gRPC Server
created a default template in Visual Studio 2019 (uses .NET Core 3.1)
Console App (works perfectly)
created a default .NET Core Console App -> added the Proto file from Server to Client and changed the gRPC Stub Classes to Client Only
uses: .NET Core 3.1
has following NuGets:
- Grpc.Tools
- Grpc.Net.Client
- Google.Protobuf
code
static async Task Main(string[] args) // works perfectly
{
using var channel = GrpcChannel.ForAddress("https://localhost:5001");
var client = new Greeter.GreeterClient(channel);
var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
System.Console.WriteLine("Greeting: " + reply.Message);
System.Console.WriteLine("Press any key to exit...");
System.Console.ReadKey();
}
WPF .NET Core
created a default WPF .NET Core app -> added the Proto file from Server to Client and changed the gRPC Stub Classes to Client Only
uses: .NET Core 3.1
has following NuGets:
- Grpc.Tools
- Grpc.Net.Client
- Google.Protobuf
code
Loaded += async delegate
{
using var channel = GrpcChannel.ForAddress("https://localhost:5001");
var client = new Greeter.GreeterClient(channel);
var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
};
PROBLEM
I can NOT build the WPF app
errors:
The type or namespace name 'MyProtoNamespace' does not exist in the namespace 'MyWPFNameSpace' (are you missing an assembly reference?)
.proto
file? What's the differences between the project file of the console app vs the project file of the WPF app? – mm8