Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure连接字符串-对象引用未设置为对象的实例_C#_Azure_Console Application_Azure Storage Blobs - Fatal编程技术网

C# Azure连接字符串-对象引用未设置为对象的实例

C# Azure连接字符串-对象引用未设置为对象的实例,c#,azure,console-application,azure-storage-blobs,C#,Azure,Console Application,Azure Storage Blobs,我正在尝试在Windows控制台应用程序中下载azure Blob。当我构建和调试应用程序时,我的azure连接字符串引发异常。此字符串在我的其他asp.net应用程序中运行良好 令人不快的是: CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["DefaultEndpointsProtocol=https;AccountName=xxxxx;

我正在尝试在Windows控制台应用程序中下载azure Blob。当我构建和调试应用程序时,我的azure连接字符串引发异常。此字符串在我的其他asp.net应用程序中运行良好

令人不快的是:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["DefaultEndpointsProtocol=https;AccountName=xxxxx;AccountKey=xxxxx==;BlobEndpoint=https://xxxxx.blob.core.windows.net/;TableEndpoint=https://xxxxx.table.core.windows.net/;QueueEndpoint=https://xxxxx.queue.core.windows.net/;FileEndpoint=https://xxxxx.file.core.windows.net/"].ConnectionString);
我的代码是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Configuration;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Threading;

namespace CPGetAdverts
{
    class Program
    {
        static void Main(string[] args)
        {
            // Retrieve storage account from connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["DefaultEndpointsProtocol=https;AccountName=xxxxx;AccountKey=xxxxx==;BlobEndpoint=https://xxxxx.blob.core.windows.net/;TableEndpoint=https://xxxxx.table.core.windows.net/;QueueEndpoint=https://xxxxx.queue.core.windows.net/;FileEndpoint=https://xxxxx.file.core.windows.net/"].ConnectionString);
            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            // Retrieve a reference to a container.
            var container = blobClient.GetContainerReference("newadverts").ListBlobs();
            // Retrieve filenames from container List
            var urls = new List<string>();
            int fileName = 1;

            foreach (var blob in container)
            {
                using (var fileStream = System.IO.File.OpenWrite(@"\home\pi\Pictures\" + fileName + ".jpg"))
                {
                    var blobReference = blobClient.GetBlobReferenceFromServer(blob.Uri);
                    blobReference.DownloadToStream(fileStream);
                    fileName++;
                }
            }

        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用系统集合;
使用Microsoft.WindowsAzure;
使用Microsoft.WindowsAzure.Storage;
使用Microsoft.WindowsAzure.Storage.Auth;
使用Microsoft.WindowsAzure.Storage.Blob;
使用系统配置;
使用System.IO;
使用系统数据;
使用System.Data.SqlClient;
使用系统线程;
命名空间CPGetAdverts
{
班级计划
{
静态void Main(字符串[]参数)
{
//从连接字符串中检索存储帐户。
CloudStorageAccount-storageAccount=CloudStorageAccount.Parse(ConfigurationManager.ConnectionString[“DefaultEndpointsProtocol=https;AccountName=xxxxx;AccountKey=xxxxx==;BlobEndpoint=https://xxxxx.blob.core.windows.net/;表端点=https://xxxxx.table.core.windows.net/;队列端点=https://xxxxx.queue.core.windows.net/;文件端点=https://xxxxx.file.core.windows.net/“].连接字符串);
//创建blob客户端。
CloudBlobClient blobClient=storageAccount.CreateCloudBlobClient();
//检索对容器的引用。
var container=blobClient.GetContainerReference(“newadverts”).ListBlobs();
//从容器列表中检索文件名
var url=新列表();
int fileName=1;
foreach(容器中的var blob)
{
使用(var fileStream=System.IO.File.OpenWrite(@“\home\pi\Pictures\”+fileName+”.jpg))
{
var blobReference=blobClient.GetBlobReferenceFromServer(blob.Uri);
blobreeference.DownloadToStream(fileStream);
文件名++;
}
}
}
}
}
例外情况是:

System.NullReferenceException未经处理,HResult=-2147467261
消息=对象引用未设置为对象的实例。
Source=CPGetAdverts StackTrace: 在c:\Users\Diarmaid\Documents\visualstudio中的CPGetAdverts.Program.Main(字符串[]args)处 2015\Projects\cpgetadvists\cpgetadvists\Program.cs:24行 位于System.AppDomain.\u nExecuteAssembly(RuntimeAssembly程序集,字符串[]args) 位于System.AppDomain.ExecuteAssembly(字符串汇编文件、证据汇编安全性、字符串[]args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()上 位于System.Threading.ThreadHelper.ThreadStart\u上下文(对象状态) 位于System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext、ContextCallback回调、对象状态、布尔值 (同步CTX) 在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔值 (同步CTX) 在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态) 位于System.Threading.ThreadHelper.ThreadStart()的内部异常:


有人有什么想法吗?

我希望ConfigurationManager.ConnectionString[“”]引用连接字符串的名称,而不是连接字符串本身。如果您对连接字符串进行硬编码,则不需要调用检索连接字符串


有关详细信息,请参阅。

我希望ConfigurationManager.ConnectionString[“”]引用连接字符串的名称,而不是连接字符串本身。如果您对连接字符串进行硬编码,则不需要调用检索连接字符串


有关详细信息,请参阅。

除了这是一个控制台应用程序之外,我是否应该将连接字符串放入app.config或packages.config?app.config,packages.config是为nugetYou准备的。我的朋友是天才。猫在帽子里!(图像在本地驱动器中!!):)谢谢!!!!!除了这是一个控制台应用程序,我应该把我的连接字符串放进app.config还是packages.config?app.config,packages.config是给nugetYou的我的朋友是个天才。猫在帽子里!(图片在本地驱动器里!!):)谢谢!!!!!!