我正在尝试从Azure Data Lake Store文件中读取内容。但是,当连接/打开连接本身失败时,&抛出异常
var stream = _adlsFileSystemClient.FileSystem.Open(_adlsAccountName, "/folder1/"+file.PathSuffix);
将例外情况视为:
Exception of type 'Microsoft.Rest.Azure.CloudException' was thrown.
无法识别问题。 如何解决这个问题?
谢谢
答案 0 :(得分:3)
Microsoft的类型' Microsoft.Rest.Azure.CloudException'被扔了。
这是基本的异常信息。因此,请尝试使用fiddler工具来捕获详细错误信息。
根据您的代码,似乎找不到文件或授权例外。
1.如果是404错误:请尝试使用以下格式并检查azure门户网站中的文件。
var srcPath = "/mytempdir/tomtest.txt";
var stream = adlsFileSystemClient.FileSystem.Open(adlsAccountName, srcPath);
2.如果是授权例外,并且您正在使用具有客户端密钥的服务到服务身份验证。请为azure AD应用程序分配权限以操作该文件。更多详情请参阅document。
以下是我的测试代码和截图:
var applicationId = "your application Id";
var secretKey = "secret Key";
var tenantId = "Your tenantId";
var adlsAccountName = "adls account name";
var creds = ApplicationTokenProvider.LoginSilentAsync(tenantId, applicationId, secretKey).Result;
var adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds);
var srcPath = "/mytempdir/tomtest.txt";
var destPath = @"F:\tom\testfile.txt";
using (var stream = adlsFileSystemClient.FileSystem.Open(adlsAccountName, srcPath))
using (var fileStream = new FileStream(destPath, FileMode.Create))
{
stream.CopyTo(fileStream);
}
Packages.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Hyak.Common" version="1.0.2" targetFramework="net452" />
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net452" />
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Azure.Management.DataLake.Store" version="1.0.4" targetFramework="net452" />
<package id="Microsoft.Azure.Management.DataLake.StoreFileSystem" version="0.9.6-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.DataLake.StoreUploader" version="1.0.1-preview" targetFramework="net452" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net452" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net452" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net452" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net452" />
<package id="Microsoft.Net.Http" version="2.2.22" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.5" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.5" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.12" targetFramework="net452" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" />
</packages>