SSIS脚本任务:无法加载文件或程序集' Microsoft.WindowsAzure.Storage,Version = 5.0.0.0,Culture = neutral

时间:2017-11-20 13:43:16

标签: c# sql-server ssis azure-storage-blobs etl

我正在使用SSDT(Sql Server数据工具)和Visual Studio 2015开展SSIS项目,我在脚本任务中引用了dll Microsoft.WindowsAzure.Storage.dll并在我的网站上使用了C#项目,但它不断抛出以下信息:

  

无法加载文件或程序集' Microsoft.WindowsAzure.Storage,Version = 5.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其中一个依赖项。系统找不到指定的文件。

我已经尝试使用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);
    }
你可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

之前我使用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

答案 1 :(得分:0)

您可以将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,谢谢Script task to upload zip file to blob storage with azure datafactory SSIS