I wrote a a protobuf file in my C# ASP.NET Core gRPC Service project, trying to follow the example, and now I need to write the code for it, but it doesn’t seem to be able to find the class name. I edited the .csproject
file as many others have suggested to add the path to the .proto
file, but it still doesn’t seem to be working. How can I fix the problem and compile the service?
This error is being produced:
CS0246 The type or namespace name 'Database' could not be found (are you missing a using directive or an assembly reference?)
Below is the .proto file, Protosdatabase.proto
, which I wrote:
syntax = "proto3";
option csharp_namespace = "LiteDistCoordinator.Protos";
enum DataType {
NULL = 0;
INTEGER = 1;
REAL = 2;
TEXT = 3;
BLOB = 4;
}
message Table {
int64 columns = 1;
int64 rows = 2;
repeated DataType column_data_types = 3;
repeated Value data = 4;
}
service DatabaseService {
rpc CreateTable(CreateTableRequest) returns (NonQueryResponse);
rpc InsertInto(InsertIntoRequest) returns (NonQueryResponse);
rpc UpdateAll(UpdateAllRequest) returns (NonQueryResponse);
rpc UpdateWhere(UpdateWhereRequest) returns (NonQueryResponse);
rpc SelectFrom(SelectFromRequest) returns (QueryResponse);
rpc SelectAllFrom(SelectAllFromRequest) returns (QueryResponse);
rpc SelectFromWhere(SelectFromWhereRequest) returns (QueryResponse);
rpc SelectAllFromWhere(SelectAllFromWhereRequest) returns (QueryResponse);
rpc DeleteFrom(DeleteFromRequest) returns (NonQueryResponse);
rpc DeleteAllFrom(DeleteAllFromRequest) returns (NonQueryResponse);
rpc DropTable(DropTableRequest) returns (NonQueryResponse);
}
message NonQueryResponse {
int32 status_code = 1;
string error_message = 2;
}
message QueryResponse {
int32 status_code = 1;
string error_message = 2;
Table table_data = 3;
}
message CreateTableRequest {
string table_name = 1;
repeated ColumnDefinition columns = 2;
}
message InsertIntoRequest {
string table_name = 1;
repeated string columns = 2;
repeated ColumnValuePair values = 3;
}
message ColumnDefinition {
string name = 1;
DataType type = 2;
}
message UpdateAllRequest {
string table_name = 1;
repeated ColumnValuePair new_values = 2;
}
message UpdateWhereRequest {
string table_name = 1;
repeated ColumnValuePair new_values = 2;
string conditions = 3;
}
message SelectFromRequest {
string table_name = 1;
repeated string columns = 2;
}
message SelectAllFromRequest {
string table_name = 1;
}
message SelectFromWhereRequest {
string table_name = 1;
repeated string columns = 2;
string conditions = 3;
}
message SelectAllFromWhereRequest {
string table_name = 1;
string conditions = 2;
}
message DeleteFromRequest {
string table_name = 1;
string conditions = 2;
}
message DeleteAllFromRequest {
string table_name = 1;
}
message DropTableRequest {
string table_name = 1;
}
message Value {
oneof value_type {
string string_value = 1;
int64 int_value = 2;
double real_value = 3;
bytes blob_value = 4;
NullValue null_value = 5;
}
}
message ColumnValuePair {
string column = 1;
Value value = 2;
}
message NullValue {}
Below is the C# code, ServicesDatabaseService.cs
, where the error occurs:
using Grpc.Core;
using LiteDistCoordinator;
namespace LiteDistCoordinator.Services
{
public class DatabaseService : Database.DatabaseBase // PROBLEM HERE: the class name "Database" has a red squiggly under it
{
private readonly ILogger<DatabaseService> _logger;
public DatabaseService(ILogger<DatabaseService> logger)
{
_logger = logger;
}
// code not written yet...
}
}
Here is the .csproj
file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Protobuf Include="Protosgreet.proto" GrpcServices="Server" />
<Protobuf Include="Protostestlist.proto" GrpcServices="Server" />
<Protobuf Include="Protosdatabase.proto" GrpcServices="Server" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.57.0" />
<PackageReference Include="Grpc.Tools" Version="2.63.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>