Bot Framework V4调用Skill时uriString空值异常排查求助
I've been working through the Bot Framework Integrate Composer Into Skill Project tutorial to integrate Composer dialogs into a Skill project, including calling a Skill dialog built with Composer. Everything was going smoothly until I hit a roadblock: when triggering the Skill call, I get the error:
"Value cannot be null. (Parameter 'uriString')"
Reproduction Steps
- Switch to the
skill-setting-issuebranch of the repository, and install Bot Emulator. - Open
Integrate-Composer-Dialog-Using-Skill.slnin Visual Studio, set a breakpoint at line 79 ofDefaultAdapter.cs. - Start debugging, connect to
http://localhost:3978/api/messagesvia Bot Emulator. - Type "Greeting"—the Bot returns the expected response, confirming the Composer dialog integration works fine.
- Type "Skill"—the breakpoint hits, and the above error is thrown.
Root Cause Analysis
The error fires at line 156 of BeginDialogAsync in Microsoft.Bot.Builder.Dialogs.Adaptive.BeginSkill, when populating DialogOptions.SkillHostEndpoint. After digging into the code, I suspect the configuration values in lines 52-57 of Composer-With-Skill.dialog (like "skillHostEndpoint": "=settings.skillHostEndpoint") aren't being resolved from ComposerDialogs\settings\appsettings.json. If I hardcode the actual values instead of using the settings reference, the Skill call works perfectly (as seen in the master branch).
I did add the Composer settings file in line 51 of Startup.cs as per the tutorial, but the configuration doesn't seem to be taking effect.
Troubleshooting Attempts
- Adding
skillHostEndpointdirectly to the mainappsettings.jsonworks, but this isn't the desired setup per the tutorial. - Moving the Composer settings file to different locations, renaming it, and updating
Startup.csaccordingly didn't fix the issue. - Removing the configuration from the main
appsettings.jsondidn't change anything—BeginSkill.csstill couldn't access the values, confirming theStartup.csconfig setup isn't working.
Solutions to Fix the Configuration Resolution
Here are the steps I found to resolve this issue:
- Verify Configuration Loading Logic in Startup.cs
Make sure the Composer settings file is added to the configuration builder in the correct order (after the main appsettings, so it doesn't get overridden). Your code should look something like this:
var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) // Load Composer's settings file .AddJsonFile("ComposerDialogs/settings/appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); Configuration = builder.Build();
Double-check the file path matches where your Composer settings are stored.
Confirm the Settings File is Copied to Output
Right-clickComposerDialogs/settings/appsettings.jsonin Visual Studio, go to Properties, and set Copy to Output Directory to Copy if newer or Copy always. This ensures the file is available in the debug folder when the app runs.Validate Configuration is Loaded
Add a quick debug check inStartup.csafter building the configuration to confirm the value is being pulled in:
var skillHostEndpoint = Configuration["skillHostEndpoint"]; Console.WriteLine($"Loaded skillHostEndpoint: {skillHostEndpoint}");
If this outputs null, your file path is incorrect or the file isn't being copied correctly.
- Check Adaptive Dialog Expression Syntax
Ensure the expression inComposer-With-Skill.dialogmatches how your configuration is structured. If yourappsettings.jsonhas a nestedsettingsobject like:
{ "settings": { "skillHostEndpoint": "http://your-endpoint" } }
Then the expression should be "=settings.skillHostEndpoint". If the value is at the root level of the config file, use "=skillHostEndpoint" instead. Some Bot Framework versions also use configuration as the prefix, so you can try "=configuration.skillHostEndpoint" if needed.
- Ensure Dialog Manager Has Access to Configuration
When initializing yourDialogManagerorAdaptiveDialog, make sure the configuration is passed into the dialog context. For example, you can bind the configuration to the dialog's state so the adaptive expressions can resolve thesettingsvariables correctly.
Final Notes
This issue boils down to the Composer settings file not being properly loaded into the Bot Framework's configuration system, so the adaptive dialog can't resolve the settings references. By fixing the configuration loading logic and verifying the file is accessible, you should be able to resolve the uriString null error.
内容的提问来源于stack exchange,提问作者alexabru

