我正在使用 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/