简体   繁体   English

从OSX(Mac)上的控制台应用程序访问Azure存储帐户

[英]Accessing Azure storage account from console app on OSX (Mac)

I am writing code using VS 2017 community edition for Mac and trying to access a Blob on Azure storage account. 我正在使用VS 2017 Community Edition for Mac编写代码,并尝试访问Azure存储帐户上的Blob。 However, I am running into exceptions as shown in the code below. 但是,我遇到了如下代码所示的异常。

The WindowsAzure.Storage version is 9.1.1 WindowsAzure.Storage版本为9.1.1

using System;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;

namespace storageaccount
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnection"));

            //var blobClient = storageAccount.CreateCloudBlobClient();

            //var container = blobClient.GetContainerReference("images");

               //container.CreateIfNotExists(Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Blob);

        //Console.ReadKey();
        }
    }
}

Exception thrown from the afore-mentioned code: 从上述代码引发的异常:

System.DllNotFoundException: fusion.dll
  at at (wrapper managed-to-native) Microsoft.Azure.NativeMethods.CreateAssemblyCache(Microsoft.Azure.NativeMethods/IAssemblyCache&,int)
  at Microsoft.Azure.NativeMethods.GetAssemblyPath (System.String name) [0x00037] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
  at Microsoft.Azure.AzureApplicationSettings.GetServiceRuntimeAssembly () [0x0000d] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
  at Microsoft.Azure.AzureApplicationSettings..ctor () [0x0001a] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
  at Microsoft.Azure.CloudConfigurationManager.get_AppSettings () [0x0001e] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
  at Microsoft.Azure.CloudConfigurationManager.GetSetting (System.String name, System.Boolean outputResultsToTrace) [0x00039] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
  at Microsoft.Azure.CloudConfigurationManager.GetSetting (System.String name) [0x00000] in <bcbac5dcfbdd47eabe8212983b7d996d>:0
  at storageaccount.MainClass.Main (System.String[] args) [0x00001] in /Users/Projects/storageaccount/storageaccount/Program.cs:11

What's wrong with the code? 代码有什么问题? I am using Nuget package to access cloud storage account. 我正在使用Nuget程序包访问云存储帐户。 From the exception thrown it is not clear if this is supported on OSx. 从引发的异常尚不清楚OSx是否支持此功能。

Any help is appreciated. 任何帮助表示赞赏。

Additional information: I see that there are two project options in VS 2017 (for Mac) while creating a new project. 附加信息:我看到在创建新项目时,VS 2017(对于Mac)有两个项目选项。 1. .Net core console app 2. .Net console app (under .Net option) - What does this run against? 1. .Net核心控制台应用程序2. .Net控制台应用程序(在.Net选项下)- 此操作针对什么?

Thanks 谢谢

As you mentioned that Microsoft.WindowsAzure.ConfigurationManager is .net framework package, it is not compatible with .net core platform . 如您所提到的,Microsoft.WindowsAzure.ConfigurationManager是.net框架包,它与.net核心平台不兼容

I am still looking for information on how to read app.config for .Net application on Mac 我仍在寻找有关如何在Mac上阅读适用于.Net应用程序的app.config的信息

You could use the System.Configuration.ConfigurationManager to do that. 您可以使用System.Configuration.ConfigurationManager来做到这一点。

 var storeageString = ConfigurationManager.AppSettings["storagestring"];

App.config App.config中

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="storagestring" value ="Test string"/>
  </appSettings>
</configuration>

Another way is that you could add appsettings.json to a .NET Core console app. 另一种方法是,您可以将appsettings.json添加到.NET Core控制台应用程序。

All that's required is to add the following NuGet packages and an appsettings.json file. 所需要做的就是添加以下NuGet包和一个appsettings.json文件。

  • Microsoft.Extensions.Configuration Microsoft.Extensions.Configuration

  • Microsoft.Extensions.Configuration.FileExtensions Microsoft.Extensions.Configuration.FileExtensions

  • Microsoft.Extensions.Configuration.Json Microsoft.Extensions.Configuration.Json

Demo code 演示代码

var builder = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json");
IConfigurationRoot configuration = builder.Build();
var connectionString = configuration["StorageConnection"];
Console.WriteLine(connectionString);

appsettings.json file: appsettings.json文件:

{
    "StorageConnection": "Test Connection string"
}

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 已删除 Azure Function App 的存储帐户。 - Deleted Storage Account for Azure Function App. C# Visual Studio 2019 for Mac在Mac OS上运行的代码无法读写本地Azure Storage Account Emulator - The C# code running on Mac OS by Visual Studio 2019 for Mac is unable to write and read to/from the local Azure Storage Account Emulator 控制台应用程序使用 azure 存储 tableapi - Console app to use azure storage tableapi 以编程方式访问存储帐户 - Accessing Storage account programmatically 从Azure存储Blob访问元数据 - Accessing metadata from azure storage blob 从UWP应用程序访问Azure表存储的首选方法是什么? - What's the preferred method for accessing Azure table storage from a UWP app? 获取 RequestFailedException:访问 Azure 中的 Blob 存储时,不允许对此存储帐户进行公共访问 - Getting RequestFailedException: Public access is not permitted on this storage account when accessing Blob Storage in Azure 更改存储帐户连接字符串后 Azure Function App 无法正常工作 - Azure Function App not working after changing storage account connection string 使用Xamarin开发跨平台应用程序时使用C#从Azure存储帐户表中检索记录,并给出错误 - Retrieving records from Azure Storage account table using c# while developing cross platform app using xamarin giving error 在Blob中将Blob从一个存储帐户复制到另一个存储帐户 - Copy Blob from one storage account to another in Azure in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM