简体   繁体   English

如何修复 gRPC 和 C# 的“命名空间名称“故障”的类型在命名空间中不存在”?

[英]How to fix "The type of namespace name "Fault" does not exist in the namespace" for gRPC and C#?

I've defined a lot of types and methods (messages and services in proto-lingo) and got stuck on this problem.我已经定义了很多类型和方法(原始语言中的消息和服务)并被困在这个问题上。 Sometimes when I make changes I get this very unhelpful error message.有时,当我进行更改时,我会收到这个非常无用的错误消息。

The type of namespace name "Fault" does not exist in the namespace 'MyApp.MyDomain' (are you missing an assembly reference?) 

I'm using Visual Studio 2017 and compile to C#.我正在使用 Visual Studio 2017 并编译为 C#。

I'm answering my own question because I get a feeling this is a common problem.我正在回答我自己的问题,因为我觉得这是一个常见问题。 It's also hard enough to figure out because the error message is (although helpful) very general.这也很难弄清楚,因为错误消息(虽然有帮助)非常普遍。 Ie you get the same error message all the time for various reasons.也就是说,由于各种原因,您始终会收到相同的错误消息。

The solution was to set the "Build Action"-property for each .proto file to build using the protobuf compiler.解决方案是为每个 .proto 文件设置“构建操作”属性,以使用 protobuf 编译器进行构建。

Do this:做这个:

  1. Right click on your .proto file in the Visual Studio solution explorer.在 Visual Studio 解决方案资源管理器中右键单击 .proto 文件。
  2. Choose "Properties"选择“属性”
  3. Change "Build action" to "Protobuf compiler"将“构建操作”更改为“Protobuf 编译器”

Your .cs files should now be generated in your folder ./project/MyProject/obj/Debug/netstandard2.0/ folder (or similar destination folder).您的 .cs 文件现在应该在您的文件夹./project/MyProject/obj/Debug/netstandard2.0/文件夹(或类似的目标文件夹)中生成。

I ran into this but in my situation, I had an import statement.我遇到了这个,但在我的情况下,我有一个导入声明。 The import statement is case sensitive.导入语句区分大小写。

"project/myClass/v1/ mytest .proto" => "project/myClass/v1/ myTest .proto" "project/myClass/v1/ mytest .proto" => "project/myClass/v1/ myTest .proto"

暂无
暂无

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

相关问题 c#错误名称空间中不存在类型或名称空间名称'SampleMain' - c# error The type or namespace name 'SampleMain' does not exist in the namespace 具有正确的名称空间和目录时,如何解决C#中的“类型名称不存在”错误 - How to fix 'The type name does not exist' error in C# while having the correct namespace and the directory 类型或名称空间名称不存在-C#中的文件夹 - The type or namespace name does not exist - folders in C# 如何解决“名称空间Y中不存在类型或名称空间名称X”的错误? - How do I fix error saying “The type or namespace name X does not exist in the namespace Y”? C#| 类型或名称空间ParamaterizedThreadStart不存在 - c# | the type or namespace ParamaterizedThreadStart does not exist C#WPF-名称“…”在命名空间“ clr-namespace:…”中不存在 - C# WPF - The name “…” does not exist in the namespace “clr-namespace:…” 我在 C# 中收到错误“命名空间中不存在类型或命名空间名称” - I get an error in C# "The type or namespace name does not exist in namespace" Unity 4.6 C#:类型或名称空间名称“ IOS”在名称空间“ GooglePlayGames”中不存在 - Unity 4.6 C#: The type or namespace name `IOS' does not exist in the namespace `GooglePlayGames' c#引用错误-名称空间'EntityFramework'中不存在类型或名称空间名称'Extended' - c# referencing error - The type or namespace name 'Extended' does not exist in the namespace 'EntityFramework' CS0234 C#类型或名称空间名称'Slydeextender'在名称空间中不存在(您是否缺少程序集引用?) - CS0234 C# The type or namespace name 'Slydeextender' does not exist in the namespace (are you missing an assembly reference?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM