Emanuel Lindström
Emanuel Lindström

Reputation: 2039

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#.

Upvotes: 1

Views: 3133

Answers (2)

irperez
irperez

Reputation: 1777

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"

Upvotes: 0

Emanuel Lindström
Emanuel Lindström

Reputation: 2039

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. I.e 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.

Do this:

  1. Right click on your .proto file in the Visual Studio solution explorer.
  2. Choose "Properties"
  3. Change "Build action" to "Protobuf compiler"

Your .cs files should now be generated in your folder ./project/MyProject/obj/Debug/netstandard2.0/ folder (or similar destination folder).

Upvotes: 5

Related Questions