Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' 引发异常
Posted
技术标签:
【中文标题】Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment\' 引发异常【英文标题】:Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exceptionMicrosoft.WindowsAzure.ServiceRuntime.RoleEnvironment' 引发异常 【发布时间】:2013-08-02 02:57:05 【问题描述】:WPF 新手。当我单击 WPF 应用程序中的按钮时,我想将图片上传到 azure blob。我有以下代码 1- 打开文件对话框,2- GetContainer 类。 为什么这不起作用? 私人无效btnUpload_Click(对象发送者,RoutedEventArgs e)
// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Picture"; // Default file name
//dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif"; // Filter files by extension
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
// Open document
string filename = dlg.FileName;//*********************ABOVE CODE OPENS FILES TO SELECT************************
string uniqueBlobName = Guid.NewGuid().ToString();
// Retrieve storage account from connection string.
CloudStorageAccount objStorage = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DefaultEndpointsProtocol=https;AccountName=*********;AccountKey=************)
// Create the blob client.
CloudBlobClient objclient = objStorage.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer objContainer = objclient.GetContainerReference("rewardsimageblob");
// Create the container if it doesn't already exist.
objContainer.CreateIfNotExist();
// Retrieve reference to a blob named "uniqueBlobName"
CloudBlob blob = objContainer.GetBlobReference(uniqueBlobName);
// Create or overwrite the "uniqueBlobName" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
blob.UploadFromStream(fileStream);
【问题讨论】:
【参考方案1】:我知道我们不应该提供链接作为答案。
但是这篇 Windows Azure 文章涵盖了所有内容。
How to use the Windows Azure Blob Storage Service in .NET
【讨论】:
谢谢,我进行了更改,但出现错误“并非所有路径都返回值” 您的GetContainer
方法对return
没有任何作用。将return objContainer;
添加到方法的末尾。以上是关于Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' 引发异常的主要内容,如果未能解决你的问题,请参考以下文章