Mac开发Azure Function Service Bus触发器遇401无效签名错误
解决Mac上IDE运行Service Bus触发器报401无效签名的问题
问题概述
Windows上正常运行的Service Bus触发器函数,在Mac上通过Rider或Visual Studio运行时出现以下401 InvalidSignature错误,但使用func start命令行运行无异常:
Put token failed. status-code: 401, status-description: InvalidSignature: The token has an invalid signature..
Message processing error (Action=Receive, ClientId=MessageReceiver1my-topic/Subscriptions/my-sub, EntityPath=my-topic/Subscriptions/my-sub, Endpoint=my-dev.servicebus.windows.net)
解决方案
1. 检查IDE环境变量加载
- 手动在IDE的运行配置中添加
ServiceBusConnection环境变量,直接粘贴Azure门户获取的Service Bus连接字符串,跳过local.settings.json的加载验证。 - 确认local.settings.json的属性设置里,
Copy to Output Directory已设为Copy if newer,确保IDE运行时能读取到最新配置。
2. 验证连接字符串完整性
- 直接从Azure门户复制原始连接字符串替换local.settings.json中的值,避免因跨系统复制导致的特殊字符(如
=、;)转义错误。
3. 确认IDE的Azure认证状态
- 如果使用Azure AD身份认证而非连接字符串,检查IDE是否已登录正确的Azure账号,且账号拥有该Service Bus主题/订阅的访问权限。可尝试重新登录Azure账号,或切换为连接字符串认证模式。
4. 更新IDE及Azure插件
- 将Rider/Visual Studio for Mac更新至最新稳定版本,同时更新IDE中的Azure相关插件,确保与Service Bus SDK版本兼容。
5. 清除IDE缓存
- 清除IDE缓存后重启,解决配置加载异常问题:
- Rider:
File→Invalidate Caches...→ 选择Clear file system cache and local history后重启 - Visual Studio for Mac:
Visual Studio→Preferences→Locations→ 点击Clear Cache后重启
- Rider:
内容的提问来源于stack exchange,提问作者Jonathan
相关产品推荐
相关产品推荐

