In our project we successfully use Google Protobuf for C++. Now there is a need to compile the same *.proto file to use it in C# code. I downloaded the recent Protobuf version 3.0.0-alpha-3. It provides support of proto2 format for C#, which is sufficient for me. I can build my *.proto file successfully and get a *.cs file. However, when I add the resulting *.cs file to my C# project and try to build, I receive compiler errors like these: "The type or namespace name 'Google' could not be found in the global namespace (are you missing an assembly reference?)"
This is the place, where the error happens:
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: DiagramExport.proto
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
Now I do not find any DLL etc. in the release ZIP available on the project page, which I could include as reference in my C# project. Only protoc.exe and some *.proto file are there. My simple question is: Where do I get those assemblies?
(Remark: I tried to build the project protobuf-csharp-3.0.0-alpha-3 from sources following the instructions in the README file, but failed to build it with Visual Studio 2013 Update 4 "out of the box"; I get a number of compiler errors.)
This is protobuf-c, a C implementation of the Google Protocol Buffers data serialization format. It includes libprotobuf-c , a pure C library that implements protobuf encoding and decoding, and protoc-c , a code generator that converts Protocol Buffer . proto files to C descriptor code.
Protocol buffers currently support generated code in Java, Python, Objective-C, and C++.
Using proto2 Message TypesIt's possible to import proto2 message types and use them in your proto3 messages, and vice versa. However, proto2 enums cannot be used directly in proto3 syntax (it's okay if an imported proto2 message uses them).
While not mandatory, gRPC applications often leverage Protocol Buffers for service definitions and data serialization. Most of the example code from this site uses version 3 of the protocol buffer language (proto3). The protocol buffer compiler, protoc , is used to compile .
After reading this and this documentation page I discovered that there is a possibility to install the Protocol Buffers NuGet package for my project by executing the following command in the Package Manager Console:
Install-Package Google.ProtocolBuffers
The console is accessible in Visual Studio 2013 via TOOLS --> NuGet Package Manager --> Package Manager Console. The manager downloaded the package and I got two references "Google.ProtocolBuffers" and "Google.ProtocolBuffers.Serialization" in my project which made the compiler happy. It works perfect now!
Have a look at the release notes here
Under the C# (Beta) section you will find:
Breaking: Preconditions is renamed to ProtoPreconditions
Breaking: GeneratedCodeInfo is renamed to GeneratedClrTypeInfo
So it seems the protoc.exe
that come with the Grpc.Tools
package generate "old" code. I replaced that protoc.exe
with this one and recompiled (regenerated) my classes which fixed the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With