本文介绍了CreateDirectConversation/CreateDirectConversationAsync Bot Framework 4中的ArgumentNullException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个机器人从MS Botframework 3迁移到4.我们有一个功能,每天可以向各个个人发送电子邮件.将代码移动到v4似乎有效,但是该调用从框架内部返回了错误.

I'm migrating a bot from MS Botframework 3 to 4. We had a function that would email various individuals daily. Moving the code to v4 appears valid, but the call returns an error from inside the framework.

在方法MicrosoftAppCredentials(string appId, string password, HttpClient customHttpClient)中的Microsoft.Bot.Connector.Authentication命名空间中引发了异常.错误是System.ArgumentNullException: 'Value cannot be null. Parameter name: clientId'.该方法内的customHttpClient为null.我没有看到传递HttpClient的方法.也许我的实现是错误的?

The exception is thrown in the Microsoft.Bot.Connector.Authentication namespace, in the method MicrosoftAppCredentials(string appId, string password, HttpClient customHttpClient). The error is System.ArgumentNullException: 'Value cannot be null. Parameter name: clientId'. customHttpClient inside that method is null. I do not see a way to pass along an HttpClient. Maybe my implementation is wrong?

我的代码:

ChannelAccount userAccount = new ChannelAccount(_config.UncategorizedReportToEmail, _config.UncategorizedReportToEmail);
var botAccount = new ChannelAccount(_config.BotEmail, _config.BotEmail);
var connector = new ConnectorClient(new Uri(_config.EmailServiceUrl));
MicrosoftAppCredentials.TrustServiceUrl(_config.EmailServiceUrl);
// Next line is where the exception is thrown
var conversation = connector.Conversations.CreateDirectConversation(botAccount, userAccount);
var conversationId = conversation.Id;

推荐答案

System.ArgumentNullException: 'Value cannot be null. Parameter name: clientId' 

此错误是由于无法从配置文件正确读取appID/密码而导致的.无论您使用的是.bot文件,appsettings.json文件还是web.config文件,请确保您的appID和密码正确无误.

This error is a result of appID/password not being read properly from the configuration file. Whether you're using a .bot file, a appsettings.json file, or a web.config file, please make sure your appID and password are correct.

这篇关于CreateDirectConversation/CreateDirectConversationAsync Bot Framework 4中的ArgumentNullException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 14:27