微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – CloudBlobContainer .Exists()将挂起/超时

出于某种原因,调用.Exists(),. CreateIfNotExists()和.Create()将挂起并永不返回.我实际上并没有得到超时异常,我只是认为人们可能会搜索该术语.

这是具体的代码

var container = _blobClient.GetContainerReference("report_dunderMifflin_details");

container.CreateIfNotExists(BlobContainerPublicAccesstype.Off);

//alternatively,because I kNow it doesn't exist yet
//I can just call Create and it will hang too
container.Create();

解决方法

我尝试通过Azure门户手动创建相同的容器(report_dunderMifflin_details),我得到一个例外,说:

Container names can contain only letters,numbers,and hyphens and must be lowercase. The name must start with a letter or a number. The name can’t contain two consecutive hyphens.

一旦我将容器名称从report_dunderMifflin_details更改为report-dundermifflin-details,它就运行得很好.在Windows.AzureStorage类中没有抛出任何异常,实在令人失望.

编辑1:

即使名称使用正确的格式,在已经存在的容器上调用Create()似乎也会导致调用.瘸.

编辑2:

我已经开始在Azure SDK之上编写一个外观,因此它不是很复杂,并且实现了用于模拟/测试目的的界面.我将这个辅助方法添加到我的外观中,以检查错误的建议容器名称.

private void CheckContainer(string containerName)
{
    var invalidNameMessage = "Container names can contain only letters,and hyphens and must be lowercase. The name must start with a letter or a number. The name can't contain two consecutive hyphens.";

    var anyInvalidChars = new Regex("[^0-9a-z-]");
    if (anyInvalidChars.IsMatch(containerName))
        throw new ArgumentException(invalidNameMessage);

    var startsWithHyphen = new Regex("$-");
    if (startsWithHyphen.IsMatch(containerName))
        throw new ArgumentException(invalidNameMessage);

    var twoHyphens = new Regex("--");
    if (twoHyphens.IsMatch(containerName))
        throw new ArgumentException(invalidNameMessage);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐