c# - SSIS 脚本任务 : Could not load file or assembly 'Microsoft. WindowsAzure.Storage,版本=5.0.0.0,文化=中性

标签 c# sql-server ssis azure-blob-storage etl

我正在使用 SSDT(Sql Server Data Tools)和 Visual Studio 2015 开发一个 SSIS 项目,并且我在脚本任务中引用 dll Microsoft.WindowsAzure.Storage.dll 并在我的项目中使用 C#,但它仍然存在抛出以下消息:

Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

我已经尝试使用 Windows PowerShell 解锁 DLL,在 Windows 上注册 DLL,检查是否已将 DLL 复制到项目文件夹的 bin 目录中,但根本没有结果。

public void Main()
    {
        // TODO: Add your code here
        string srcBlob = (string) Dts.Variables["User::dBlobName"].Value;
        // Substitui o nome da pasta PROCESSAR para PROCESSADOS
        string destBlobName = srcBlob.Replace((string)Dts.Variables["$Project::dSrcBlobDirectory"].Value, (string)Dts.Variables["$Project::dDestBlobDirectory"].Value);
        string srcContainerName = (string)Dts.Variables["$Project::dBlobContainer"].Value;
        string accountName = (string)Dts.Variables["$Project::dStorageAccountName"].Value;
        //byte[] storageAccessKey = Encoding.ASCII.GetBytes((string) Dts.Variables["$Project::dStorageAccessKey"].Value);
        string storageAccessKey = (string)Dts.Variables["$Project::dStorageAccessKey"].Value;

        MoveBlobInSameStorageAccount(accountName, storageAccessKey, srcContainerName, srcBlob, destBlobName);

        Dts.TaskResult = (int)ScriptResults.Success;
    }

    static void MoveBlobInSameStorageAccount(string accountName, string accountKey, string containerName, string sourceBlobName, string destBlobName)
    {
        var cred = new StorageCredentials(accountName, accountKey);
        var account = new CloudStorageAccount(cred, true);
        var client = account.CreateCloudBlobClient();
        var sourceContainer = client.GetContainerReference(containerName);
        var sourceBlob = sourceContainer.GetBlockBlobReference(sourceBlobName);
        var destinationContainer = client.GetContainerReference(containerName);
        var destinationBlob = destinationContainer.GetBlockBlobReference(destBlobName);
        destinationBlob.StartCopy(sourceBlob);
        sourceBlob.Delete(DeleteSnapshotsOption.IncludeSnapshots);
    }

你能帮忙吗?

最佳答案

我之前使用HttpClient调用Blob存储REST API。根据您的描述,您正在使用Microsoft Azure Storage Client Library for .NET ,我认为该程序集无法正确加载,因为它不在 GAC 中。您可能需要利用 AppDomain.AssemblyResolve用于加载程序集的事件处理程序,更详细的教程,可以引用How to load an Assembly in a SSIS script task that isn’t in the GAC .

关于c# - SSIS 脚本任务 : Could not load file or assembly 'Microsoft. WindowsAzure.Storage,版本=5.0.0.0,文化=中性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47393477/

相关文章:

c# - Sql 中的错误 Microsoft.SqlServer.ConnectionInfo

sql-server - SSIS 2014 和 Postgres ODBC 的连接泄漏问题

c# - owin启动类visual studio 2012出错

c# - 如何从具有多个路径的 svg 图像创建 appbar 按钮 PathIcon?

c# - 在 C# 泛型中无效?

SQL Server 删除所有超过 10 分钟的行

c# - 在 C# 中临时存储和重新设置属性值

sql-server - SQL Azure 数据库。使用非安全连接字符串登录

sql-server - SSIS - ANSI 平面文件始终保存为 UTF-8(无 BOM)

sql-server-2008 - 如何在 SSIS 的执行 SQL 任务中使用参数映射?