由于某种原因,调用 .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
),但我收到一个异常,指出:
一旦我将容器名称从 report_dunderMifflin_details
更改为 report-dundermifflin-details
,它就可以正常工作。在 Windows.AzureStorage 类中没有抛出异常真的很令人失望。
编辑1:
即使名称使用正确的格式,在已经存在的容器上调用 Create()
似乎也会导致调用。瘸。
编辑2:
我已经开始在 Azure SDK 之上编写外观,因此它不是很复杂,并实现了用于模拟/测试目的的接口(interface)。我将此辅助方法添加到我的外观中以检查建议的错误容器名称。
private void CheckContainer(string containerName)
{
var invalidNameMessage = "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.";
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);
}
关于c# - CloudBlobContainer .Exists() 将挂起/超时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20980522/