skip to Main Content

I am not understanding how to use this NuGet package manager in Visual Studio 2019

I installed the Grpc.Tools package from Nuget package manager.

I clicked the checkbox next to the package on solution,
But it shows there is no reference to

using Grpc.Core;

I dont see Grpc.Core under references anywhere,

And when I searched the references I could not find GRPC anywhere

Am I missing something, is there another step to installation?

enter image description here

enter image description here

My code is simple, its below

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Grpc.Core;

namespace gRPCtest
{
    public class Server : Form
    {
        public Server()
        {
            Text = "Server Window";
            Size = new System.Drawing.Size(300, 200);
        }
    }
    public class Client : Form
    {
        public Client()
        {
            Text = "Client Window";
            Size = new System.Drawing.Size(300, 200);
        }
    }

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Create a new instance of the child window
            Server serverForm = new Server();
            serverForm.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // Create a new instance of the child window
            Client clientForm = new Client();
            clientForm.Show();
        }
    }
}

In the terminal I tried running the following commands and got errors:

PS C:UsersWaymoDesktopprf.netgRPCtest> NuGetInstall-Package Grpc.Core
NuGetInstall-Package : The module 'NuGet' could not be loaded. For more information, run 'Import-Module NuGet'.
At line:1 char:1
+ NuGetInstall-Package Grpc.Core
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (NuGetInstall-Package:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoLoadModule
PS C:UsersWaymoDesktopprf.netgRPCtest> Import-Module NuGet
Import-Module : The specified module 'NuGet' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module NuGet
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (NuGet:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
    

2

Answers


  1. The .NET Framework does not actually implement HTTP/2, which is a requirement of the gRPC protocol. Therefore, the .NET Framework has limited support for gRPC based on HTTP/2.

    It seems that you performed the above operations in the WinForms (.net framework) project. Similarly, I encountered a similar situation to yours in the Winforms (.net framework) project. gRPC Tools did not appear in the project references after being successfully added.

    But in Winforms (referring to .net-based Winforms), gRPC Tools can be successfully added to the reference. You can use Winforms based on .net to perform corresponding operations.

    enter image description here

    enter image description here

    enter image description here

    For details, please refer to:

    https://learn.microsoft.com/en-us/aspnet/core/grpc/supported-platforms?view=aspnetcore-6.0#net-grpc-client-requirements

    https://learn.microsoft.com/en-us/aspnet/core/grpc/netstandard?view=aspnetcore-6.0#net-framework

    Login or Signup to reply.
  2. For the client side with gRPC in C# you should be using the Grpc.Net.Client package (and for the server side the Grpc.AspNetCore.Server package). The Grpc.Core package is in a maintenance mode and will not be used anymore. However, as @wenbingeng-MSFT pointed out in his answer, using the Grpc.Net.Client package is not a good idea if you are having problems with the HTTP/2 protocol implementation of gRPC.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search