C#的Protoc 3.9编译输出失败

时间:2019-07-13 01:45:12

标签: c# google-assistant-sdk protoc

运行时环境:.net core 2.2,.net framework 4.6.1的相同问题

在尝试为Google Assistant SDK的C#创建gRPC绑定时,在EmbeddedAssistant.g.cs中出现编译时错误 “无法从System.Type转换为Google.Type”

可供下载的项目

https://drive.google.com/file/d/1Pbmg0Zk-ozXHkWT6a6FMmBt79MTHn7_t/view?usp=sharing

我在Google.Protobuf上也遇到了错误

“类型”是一个名称空间,但其使用方式类似于类型。

详细信息

我关注了instructions to integrate google assistant for C# (Other languages: gRPC)

  1. clone Google APIs on local disk
  2. 我下载了 Protoc Compiler latest release
  3. 按照说明生成EmbeddedAssistant.g.cs文件
  4. 更早之前,Google.Protobuf.Collections和Google.Protobuf.Reflection不可用引发了错误,因此我从##的链接下载了 protobuf-csharp-3.9.0.zip 2,将Google.Protobuf文件夹复制到我的项目文件夹中,该错误消失了。

  5. 对于Google.API和Google.Type错误,我遵循此 Stackoverflow article 并已解决。

编译输出,错误是:

   descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
          new pbr::FileDescriptor[] { global::Google.Api.AnnotationsReflection.Descriptor, global::Google.Type.LatlngReflection.Descriptor, },
          new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.AssistRequest), global::Google.Assistant.Embedded.V1Alpha2.AssistRequest.Parser, new[]{ "Config", "AudioIn" }, new[]{ "Type" }, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.AssistResponse), global::Google.Assistant.Embedded.V1Alpha2.AssistResponse.Parser, new[]{ "EventType", "AudioOut", "ScreenOut", "DeviceAction", "SpeechResults", "DialogStateOut", "DebugInfo" }, null, new[]{ typeof(global::Google.Assistant.Embedded.V1Alpha2.AssistResponse.Types.EventType) }, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.DebugInfo), global::Google.Assistant.Embedded.V1Alpha2.DebugInfo.Parser, new[]{ "AogAgentToAssistantJson" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.AssistConfig), global::Google.Assistant.Embedded.V1Alpha2.AssistConfig.Parser, new[]{ "AudioInConfig", "TextQuery", "AudioOutConfig", "ScreenOutConfig", "DialogStateIn", "DeviceConfig", "DebugConfig" }, new[]{ "Type" }, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.AudioInConfig), global::Google.Assistant.Embedded.V1Alpha2.AudioInConfig.Parser, new[]{ "Encoding", "SampleRateHertz" }, null, new[]{ typeof(global::Google.Assistant.Embedded.V1Alpha2.AudioInConfig.Types.Encoding) }, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.AudioOutConfig), global::Google.Assistant.Embedded.V1Alpha2.AudioOutConfig.Parser, new[]{ "Encoding", "SampleRateHertz", "VolumePercentage" }, null, new[]{ typeof(global::Google.Assistant.Embedded.V1Alpha2.AudioOutConfig.Types.Encoding) }, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.ScreenOutConfig), global::Google.Assistant.Embedded.V1Alpha2.ScreenOutConfig.Parser, new[]{ "ScreenMode" }, null, new[]{ typeof(global::Google.Assistant.Embedded.V1Alpha2.ScreenOutConfig.Types.ScreenMode) }, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.DialogStateIn), global::Google.Assistant.Embedded.V1Alpha2.DialogStateIn.Parser, new[]{ "ConversationState", "LanguageCode", "DeviceLocation", "IsNewConversation" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.DeviceConfig), global::Google.Assistant.Embedded.V1Alpha2.DeviceConfig.Parser, new[]{ "DeviceId", "DeviceModelId" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.AudioOut), global::Google.Assistant.Embedded.V1Alpha2.AudioOut.Parser, new[]{ "AudioData" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.ScreenOut), global::Google.Assistant.Embedded.V1Alpha2.ScreenOut.Parser, new[]{ "Format", "Data" }, null, new[]{ typeof(global::Google.Assistant.Embedded.V1Alpha2.ScreenOut.Types.Format) }, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.DeviceAction), global::Google.Assistant.Embedded.V1Alpha2.DeviceAction.Parser, new[]{ "DeviceRequestJson" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.SpeechRecognitionResult), global::Google.Assistant.Embedded.V1Alpha2.SpeechRecognitionResult.Parser, new[]{ "Transcript", "Stability" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.DialogStateOut), global::Google.Assistant.Embedded.V1Alpha2.DialogStateOut.Parser, new[]{ "SupplementalDisplayText", "ConversationState", "MicrophoneMode", "VolumePercentage" }, null, new[]{ typeof(global::Google.Assistant.Embedded.V1Alpha2.DialogStateOut.Types.MicrophoneMode) }, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.DebugConfig), global::Google.Assistant.Embedded.V1Alpha2.DebugConfig.Parser, new[]{ "ReturnDebugInfo" }, null, null, null, null),
            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Assistant.Embedded.V1Alpha2.DeviceLocation), global::Google.Assistant.Embedded.V1Alpha2.DeviceLocation.Parser, new[]{ "Coordinates" }, new[]{ "Type" }, null, null, null)
          }));
    }

EmbeddedAssistant.g.cs 101至116行的已编译输出时出现编译器错误

Google.Protobuf ReflectionUtil.cs上类型上的

编译器错误 类型是一个名称空间,但使用起来就像类型。

 internal static readonly Type[] EmptyTypes = new Type[0];

        /// <summary>
        /// Creates a delegate which will cast the argument to the type that declares the method,
        /// call the method on it, then convert the result to object.
        /// </summary>
        /// <param name="method">The method to create a delegate for, which must be declared in an IMessage
        /// implementation.</param>
        internal static Func<IMessage, object> CreateFuncIMessageObject(MethodInfo method) =>
            GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageObject(method);

C# Project Structure. Files under Google folder /API , /Assistant and /Type were generated by Protoc 3.9.0 compiler

Errors look like this

1 个答案:

答案 0 :(得分:0)

问题已解决

我使用了此链接 https://github.com/grpc/grpc/blob/master/src/csharp/BUILD-INTEGRATION.md

基本上从googleapis添加了最低必需的.proto文件,以使Google助手正常工作。附加图片

Screenshot of what project looks like

然后添加了 Grpc和Grpc.Tools nuget软件包,并按照上述文章中的说明更改.csproj并进行了构建。

我刚刚在csproj中添加了以下内容

$this->date_filed_to_current_date = $this->cst_to_cmt + $this->cmt_to_current_date;

它生成了图像中显示的输出

构建失败,但是生成了CS文件。 提取生成的CS文件,将它们添加到您的真实项目中,然后添加 Google.Protobuf nuget包,进行构建,一切就很好了。