SSIS 脚本任务:无法加载文件或程序集'Microsoft.WindowsAzure.Storage,版本=5.0.0.0,文化=中性

SSIS Script Task: Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=5.0.0.0, Culture=neutral

我正在使用 SSDT(Sql 服务器数据工具)和 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, I assumed that the assembly could not load correctly, since it is not in the GAC. You may need to leverage an AppDomain.AssemblyResolve event handler for loading the assembly, more detailed tutorial, you could refer to How to load an Assembly in a SSIS script task that isn’t in the GAC.

您可以将 dll(包括 Microsoft.WindowsAzure.Storage.dll)添加到 Azure SSIS 运行时,如下所述: https://docs.microsoft.com/en-us/azure/data-factory/how-to-configure-azure-ssis-ir-custom-setup

谢谢Geri for doing the research: