You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用UseStorageDevelopment=true创建TopicClient时出现UriString空参数异常

问题解决:TopicClient构造函数ArgumentNullException(UriString为Null)

原因分析

你使用的TopicClient构造函数第一个参数要求传入Azure Service Bus的有效连接字符串,但你传入的"UseStorageDevelopment=true"是存储服务的配置项,并非合法的Service Bus连接字符串。这种无效参数会导致SDK内部解析Service Bus URI时失败,进而抛出提示UriString为Null的ArgumentNullException。

解决方案

  • 替换为正确的Service Bus连接字符串
    从Azure门户获取你的Service Bus命名空间连接字符串,格式示例如下:

    Endpoint=sb://your-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=your-access-key
    

    修改代码为:

    var serviceBusConnStr = "Endpoint=sb://your-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=your-access-key";
    var topic = new TopicClient(serviceBusConnStr, "your-topic-name");
    
  • 核对构造函数参数类型
    代码中的第二个参数anyObject必须是主题名称(字符串类型),确保参数类型匹配,避免因类型不匹配引发隐性错误。

  • 本地开发模拟方案(可选)
    如果是本地开发需要模拟Service Bus环境,可使用Azure Service Bus Emulator,它提供本地可用的连接字符串,而非存储配置项。Emulator默认连接字符串示例:

    Endpoint=sb://localhost/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=your-emulator-key
    

内容的提问来源于stack exchange,提问作者Jaider Osorio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 18:15:38