我在逐行检查我的代码后得到了答案。在调用 EventProcessorHost 的构造函数时缺少一个参数:leaseContainerName。
解决方案是使用这个:
public EventProcessorHost(string hostName, string eventHubPath, string consumerGroupName, string eventHubConnectionString, string storageConnectionString, string leaseContainerName, string leaseBlobPrefix = null);
以前我用这个:
public EventProcessorHost(string hostName, string eventHubPath, string consumerGroupName, string eventHubConnectionString, string storageConnectionString);
供参考检查此链接:
https ://developers.de/blogs/damir_dobric/archive/2016/09/12/how-to-configure-eventprocessorhost-for-iothub.aspx