首页 > 解决方案 > 简单 Azure 示例中的异常?

问题描述

我正在 C++ 中尝试 Azure(VS 2019)并获得了这里推荐的 vcpkg 包(32 位和 64 位) https://azure.github.io/azure-storage-cpp/ 然后在这里尝试了示例 https:// docs.microsoft.com/en-us/azure/storage/blobs/storage-c-plus-plus-how-to-use-blobs

我启动了一个新的 C++ 控制台应用程序并做到了这一点

#include <iostream>
#include <was\blob.h>
#include <was\storage_account.h>

int main()
{
    std::cout << "Hello World!\n";

    utility::string_t name = L"--------"; // my stuff blotted out
    utility::string_t key = L"---------"; // my stuff blotted out
    utility::string_t con = L"DefaultEndpointsProtocol=https;AccountName=" + name + L";AccountKey=" + key;

    // Define the connection-string with your values.
    const utility::string_t storage_connection_string(con);

    // Retrieve storage account from connection string.
    azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

    // Create the blob client.
    azure::storage::cloud_blob_client blob_client = storage_account.create_cloud_blob_client();

    // Retrieve a reference to a previously created container.
    azure::storage::cloud_blob_container container = blob_client.get_container_reference(U("demo"));

    // Retrieve reference to a blob named "my-blob-2".
    azure::storage::cloud_block_blob text_blob = container.get_block_blob_reference(U("Job.ini"));

    // Download the contents of a blog as a text string.
    utility::string_t text = text_blob.download_text();

执行 download_text() 调用会引发异常。

在 64 位中,它只是一个“xxx 处的异常”消息,然后是一个对话框,说明 IsCompleted() 的断言失败。在 32 位中,它在对话框之前的第二条消息中显示了更多详细信息,因为“ESP 的值没有在函数调用中正确保存”我也尝试了 download_to_stream() 示例,结果相同。帐户很好,容器和 blob 存在,blob 客户端和容器步骤很好,数据看起来还不错,只是在尝试实际拉下某些东西时失败了。

标签: c++azure

解决方案


对不起,伙计们。这是在有缺陷的最终用户类中 - 我使用了错误的存储帐户并且不理解异常。请忽略。


推荐阅读