在GetConversationMembersWithHttpMessagesAsync执行时,值不能为null(clientId)

时间:2019-06-01 23:10:06

标签: c# nullpointerexception botframework clientid

漫游器出现错误“值不能为空。参数名称:clientId”
在执行GetConversationMembersWithHttpMessagesAsync方法以获取对话用户数据时。错误和堆栈跟踪的全文:

是否有必要在Azure上创建Bot渠道注册以维护此类操作?

我已将带有不记名令牌的CustomHeaders手动添加到http查询中,但没有结果。

customHeaders.Add("Authorization", new List<string> { "Bearer " + Global.accessToken });
membersListResponse = await connector.Conversations.GetConversationMembersWithHttpMessagesAsync(convId, customHeaders);

错误和堆栈跟踪:

值不能为null。 参数名称:Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential..ctor上的clientId(字符串clientId,字符串clientSecret)    在Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials。<> c__DisplayClass8_0。<。ctor> b__0()    在System.Lazy 1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy 1.ExecutionAndPublication(LazyHelper执行AndPublication,布尔值useDefaultConstructor)处    在System.Lazy 1.CreateValue() at Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.GetTokenAsync(Boolean forceRefresh) at Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Bot.Connector.Conversations.GetConversationMembersWithHttpMessagesAsync(String conversationId, Dictionary 2 customHeaders处,在CancellationToken处cancelToken)

1 个答案:

答案 0 :(得分:0)

此异常的原因是用于发布异步请求的ConnectorClient中缺少身份验证数据。

我实例化了新的MicrosoftAppCredentials类,将appId和appPassword传递给它,然后将新实例应用于ConnectorClient。 它是: var connector = new ConnectorClient(new Uri(context.Activity.ServiceUrl))

变成: var connector = new ConnectorClient(new Uri(context.Activity.ServiceUrl), BotCredentials.msAppCredentials);