简体   繁体   English

运行带有错误的C#protobuf示例

[英]run C# protobuf example with errors

Newbie in C#, I installed Rider on MacOS and installed Google.Protobuf and protobuf-net in the solution. 我是C#的新手,我在MacOS上安装了Rider,并在解决方案中安装了Google.Protobuf和protobuf-net。 And I find the example of C# protobuf on link , and add the files into the solution. 我在link上找到了C#protobuf的示例,并将文件添加到解决方案中。 However, when I compile the .cs files, I got those errors. 但是,当我编译.cs文件时,出现了这些错误。

Addressbook.cs(263, 57): [CS1615] Argument 1 may not be passed with the 'ref' keyword Addressbook.cs(263,57):[CS1615]参数1可能无法与'ref'关键字一起传递
Addressbook.cs(445, 61): [CS1615] Argument 1 may not be passed with the 'ref' keyword Addressbook.cs(445,61):[CS1615]参数1可能无法与'ref'关键字一起传递
Addressbook.cs(580, 57): [CS1615] Argument 1 may not be passed with the 'ref' keyword Addressbook.cs(580,57):[CS1615]参数1可能无法与'ref'关键字一起传递

So how to solve these problems? 那么如何解决这些问题呢?

It seems like the methods argument do not accept a reference: ref argument ; 这似乎是方法的参数不接受一个参考: ref argument ;

To resolve this issue make sure to remove the ref before the arguments in the lines 263, 445, 580 of the Addressbook.cs file. 若要解决此问题,请确保删除Addressbook.cs文件的第263、445、580行中的参数之前的ref

example given: 给出的例子:

if (!pb::UnknownFieldSet.MergeFieldFrom(ref _unknownFields, input)) {
          return;
}

should be: 应该:

if (!pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input)) {
          return;
}

By comparing the official examples and protoc --csharp_out files, I found that the difference appears in the clause mentioned by @nnty. 通过比较官方示例和protoc --csharp_out文件,我发现差异出现在@nnty提到的子句中。 In the official examples, that clause is replaced by 在官方示例中,该子句被替换为

_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);

so change all the error place with above sentence may help solve the problem. 因此,用上述句子更改所有错误的位置可能有助于解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM