Bot Framework V4:值不能为null.(参数"uriString") [英] Bot Framework V4: Value cannot be null. (Parameter 'uriString')

查看:78
本文介绍了Bot Framework V4:值不能为null.(参数"uriString")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注本教程( Bot框架集成将作曲家纳入技能项目),以将作曲家对话框与技能项目集成在一起.这包括由作曲家创建的调用技能的对话框.我遇到了例外,值不能为null.(参数"uriString")"调用技能时.

I have been following the tutorial (Bot Framework Integrate Composer Into Skill Project) to integrate composer dialogs with a skill project. This includes composer created dialogs which call a skill. I am running into the exception "Value cannot be null. (Parameter 'uriString')" when calling the skill.

设置此设置时,我遇到了其他各种问题,如下所述

I ran into various other issues when setting this up, as outlined here Previous Issues, which have been resolved though I had to do a work around to get the settings to work. I now need to determine why the configuration settings are not resolving.

要重新创建问题,请使用技能设置问题"回购分支 Git回购

To recreate the issue use the "skill-setting-issue" branch of the repo Git Repo

先决条件

安装Bot仿真器: Bot仿真器安装说明

在Visual Studio Integrate-Composer-Dialog-Using-Skill.sln中打开解决方案文件

Open the solution file in visual studio Integrate-Composer-Dialog-Using-Skill.sln

在DefaultAdapter.cs的第79行上放置一个断点-这是可以看到错误的地方

Put a breakpoint on line 79 of DefaultAdapter.cs - this is where the error can be seen

开始调试项目

开放式机器人模拟器

连接到bot:http://localhost:3978/api/messages

Connect to the bot: http://localhost:3978/api/messages

键入问候"

Bot应回复您好,我已经认识到您说的问候".-这意味着作曲家对话框的集成工作按预期进行.

Bot should respond with "Hello, I have recognized that you said greeting" - This means that the composer dialog integration is working as expected.

输入技能"

DefaultAdapter.cs的第79行上的断点应触发,以提供错误的详细信息.

The breakpoint on line 79 of DefaultAdapter.cs should trigger giving details of the error.

该错误似乎是由于第52行和第52行之间的Composer-With-Skill.dialog中的设置值而发生的.57无法解决.

The error seems to be occurring because the settings values within Composer-With-Skill.dialog between line 52 & 57 cannot be resolved.

"botId": "=settings.MicrosoftAppId",
"skillHostEndpoint": "=settings.skillHostEndpoint",
"connectionName": "=settings.connectionName",
"allowInterruptions": true,
"skillEndpoint": "=settings.skill['integrateComposerDialogUsingSkill'].endpointUrl",
"skillAppId": "=settings.skill['integrateComposerDialogUsingSkill'].msAppId",

如果我将使用= settings ....的部分替换为实际值,则该应用程序将正常运行(请参阅master分支以获取具有该设置的代码).

If I replace the portions which use =settings.... with actual values then the application works (see master branch for code which has that setup).

例如

"botId": "=settings.MicrosoftAppId",
"skillHostEndpoint": "http://localhost:3978/api/skills",
"connectionName": "=settings.connectionName",
"allowInterruptions": true,
"skillEndpoint": "http://localhost:3978/api/echo/messages",
"skillAppId": "00000000-0000-0000-0000-000000000000",

请注意,botId&connectionName未使用,因此不会导致运行时错误.

Note that botId & connectionName are not used so do not cause runtime errors.

这些值应从ComposerDialogs \ settings \ appsettings.json第67到79行中检索.

These values should be retrieved from ComposerDialogs\settings\appsettings.json line 67 through 79.

  "skill": {
    "integrateComposerDialogUsingSkill": {
      "endpointUrl": "http://localhost:3978/api/echo/messages",
      "msAppId": "00000000-0000-0000-0000-000000000000"
    }
  },
  "defaultLanguage": "en-us",
  "languages": [
    "en-us"
  ],
  "customFunctions": [],
  "skillHostEndpoint": "http://localhost:3978/api/skills"
}

ComposerDialogs \ settings \ appsettings.json已按照我遵循的教程配置为Startup.cs第51行中应用程序中的设置文件.

ComposerDialogs\settings\appsettings.json has been configured to be a setting file in the application in Startup.cs line 51 as per the tutorial I am following.

public class Startup
{
    public Startup(IWebHostEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddJsonFile("cognitivemodels.json", optional: true)
            .AddJsonFile($"cognitivemodels.{env.EnvironmentName}.json", optional: true)
            //from instructions: https://microsoft.github.io/botframework-solutions/skills/handbook/experimental-add-composer/
            .AddJsonFile($"ComposerDialogs\\settings\\appsettings.json", optional: true)
            .AddEnvironmentVariables();

我不确定为什么ComposerDialogs \ settings \ appsettings.json中的设置值无法解析Composer-With-Skill.dialog文件中的变量

I'm not sure why the variables in the Composer-With-Skill.dialog file are not being resolved by the settings values in ComposerDialogs\settings\appsettings.json

该错误发生在方法BeginDialogAsync中的文件Microsoft.Bot.Builder.Dialogs.Adaptive.BeginSkill的第156行上 Bot Builder当代码尝试填充DialogOptions.SkillHostEndpoint值时,请进入Git-BeginSkill.cs .

The error occurs on line 156 of file Microsoft.Bot.Builder.Dialogs.Adaptive.BeginSkill in method BeginDialogAsync Bot Builder Git - BeginSkill.cs when the code tries to populate the DialogOptions.SkillHostEndpoint value.

public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
        {
            if (Disabled != null && Disabled.GetValue(dc.State))
            {
                return await dc.EndDialogAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
            }

            // Update the dialog options with the runtime settings.
            DialogOptions.BotId = BotId.GetValue(dc.State);
            DialogOptions.SkillHostEndpoint = new Uri(SkillHostEndpoint.GetValue(dc.State));
            DialogOptions.ConversationIdFactory = dc.Context.TurnState.Get<SkillConversationIdFactoryBase>() ?? throw new NullReferenceException("Unable to locate SkillConversationIdFactoryBase in HostContext");
            DialogOptions.SkillClient = dc.Context.TurnState.Get<BotFrameworkClient>() ?? throw new NullReferenceException("Unable to locate BotFrameworkClient in HostContext");
            DialogOptions.ConversationState = dc.Context.TurnState.Get<ConversationState>() ?? throw new NullReferenceException($"Unable to get an instance of {nameof(ConversationState)} from TurnState.");
            DialogOptions.ConnectionName = ConnectionName.GetValue(dc.State);

将值"skillHostEndpoint":"http://localhost:3978/api/skills"放入主appsettings.json文件中,可使代码正常工作.

Putting the value, "skillHostEndpoint": "http://localhost:3978/api/skills", in the main appsettings.json file causes the code to work.

将ComposerDialogs/settings/appsettings.json移至主文件夹&重命名为appsettings-composer.json&调整startup.cs并没有帮助

moving ComposerDialogs/settings/appsettings.json up to the main folder & renaming to appsettings-composer.json & adjusting the startup.cs does not help

删除.AddJsonFile("appsettings.json",可选:true,reloadOnChange:true)不会阻止应用程序设置在BeginSkill.cs中可用.因此,这似乎表明在Startup.cs中配置构建器对可用设置没有影响.

removing .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) does not prevent the app settings from being available in BeginSkill.cs. So, this seems to indicate that configuring the builder in Startup.cs has no impact on the available settings.

推荐答案

确定已配置的IConfiguration实例&在IConfiguration上进行依赖项注入时,未使用在Startup.cs的构造函数中创建的代码.这导致添加的新配置文件不可用.

Determined that the IConfiguration instance which was configured & created in the constructor of Startup.cs was not being used when dependency injection was happening on IConfiguration. This was causing the new configuration files added not to be available.

已添加

services.AddSingleton<IConfiguration>(Configuration);

配置Startup.cs的ConfigureServices,以便检索正确的对象&这些值将可用.

To ConfigureServices of Startup.cs so that the correct object would be retrieved & the values would be available.

skill-setting-issue分支具有已更新以反映这一点.

skill-setting-issue branch of the Git Repo has been updated to reflect this.

帖子有助于确定问题.

这篇关于Bot Framework V4:值不能为null.(参数"uriString")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆