【发布时间】:2019-07-13 01:45:12
【问题描述】:
运行时环境:.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 上也遇到了错误
“Type”是一个命名空间,但使用起来像一个类型。
详情
我关注了instructions to integrate google assistant for C# (Other languages: gRPC)
- clone Google APIs on local disk
- 我下载了 Protoc Compiler latest release
- 按照说明生成 EmbeddedAssistant.g.cs 文件
早些时候它抛出错误,Google.Protobuf.Collections 和 Google.Protobuf.Reflection 不可用,所以我从 # 的链接下载了 protobuf-csharp-3.9.0.zip 2 ,将 Google.Protobuf 文件夹复制到我的项目文件夹中,该错误消失了。
对于 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 上的编译器错误类型 Type 是一个命名空间,但用作类型。
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);
【问题讨论】:
-
Error1 GeneratedClrTypeInfo 的第一个参数抛出错误
typeof(global::Google.Assistant.Embedded.V1Alpha2.AssistRequest)错误:无法从 System.Type 转换为 Google.Type 错误 2 : ** Google.Protobuf.Reflection.ReflectionUtil.cs 第 75 行及以后 ** 错误:类型是命名空间,但用作类型 -
问题我发布在协议缓冲区 github repo github.com/protocolbuffers/protobuf/issues/6388
标签: c# google-assistant-sdk protoc