gpt4 book ai didi

c# - CloudTableClient.CreateCloudTableClient 抛出 System.IO.FileNotFoundException 类型的异常

转载 作者:太空宇宙 更新时间:2023-11-03 22:44:03 24 4
gpt4 key购买 nike

enter image description here我正在构建 Outlook WEB 插件,并将 Microsoft.Azure.Storage.Common 和 Microsoft Azure.CosmosDB.Table nuget 添加到我的项目中,但最后一个显示警告:

Package 'Microsoft.Azure.CosmosDB.Table 1.1.2' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v.2.0'. This package may not be fully compatible with your project.

我在代码中引用它们并尝试访问我的表,就像文档 [1] 中显示的那样[2]如下所示,但与往常一样,没有 Microsoft 技术能够按照描述的那样在首次尝试时运行:

using Microsoft.Azure.CosmosDB.Table;
using Microsoft.Azure.Storage;
...
CloudStorageAccount cloudStorageAccount =
CloudStorageAccount.Parse(strAzureCosmosDBConnectionString);
CloudTableClient cloudTableClient = cloudStorageAccount.CreateCloudTableClient();

CloudTable cloudTable = cloudTableClient.GetTableReference("users");

TableQuery<UserEntity> tableQuery = new TableQuery<UserEntity>().Where(TableQuery.CombineFilters(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, Account),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, ID)));

await cloudTable.ExecuteQuerySegmentedAsync(tableQuery, null);

我在这一行收到内部服务器错误 500 和 System.IO.FileNotFoundException 类型的异常:

CloudTableClient cloudTableClient = cloudStorageAccount.CreateCloudTableClient();

cproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="Microsoft.Azure.CosmosDB.Table" Version="1.1.2" />
<PackageReference Include="Microsoft.Azure.Storage.Common" Version="9.4.0.2-preview" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.0.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.2.2" />
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
<PackageReference Include="Microsoft.Graph" Version="1.9.0" />
<!--<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="1.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />-->

</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<None Include="wwwroot\myHtmlTemplate.html" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

这是堆栈跟踪:

at Microsoft.Azure.CosmosDB.Table.CloudTableClient..ctor(StorageUri storageUri, StorageCredentials credentials, TableConnectionPolicy connectionPolicy, Nullable`1 desiredConsistencyLevel) at Microsoft.Azure.CosmosDB.Table.AccountExtensions.CreateCloudTableClient(CloudStorageAccount account) in d:\dbs\sh\aplrc\0506_210442\cmd\18\Product\SDK\Table.net\Lib\Common\Table\Account\AccountExtensions.cs:line 21

消息:

Could not load file or assembly 'Microsoft.Azure.Documents.Client, Version=1.20.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

最佳答案

问题是 Microsoft.Azure.CosmosDB.Table(最新版本 1.1.2) 不支持 .NET Standard。更多详情请访问https://github.com/Azure/azure-documentdb-dotnet/issues/344 .

但是,可以使用 Azure 存储 SDK(WindowsAzure.Storage 版本 9.2.0)。

下面是在 CosmosDB/Table 帐户中创建新表(如果尚不存在)的示例代码:

using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;

namespace CosmosDBTableApp
{
class Program
{
static void Main(string[] args)
{
const string ConnectionString = "{CosmosDB/Table Connection String}";
const string TableName = "{Table Name}";
CreateTableIfNotExists(ConnectionString, TableName).Wait();
}

private static async Task CreateTableIfNotExists(string connectionString, string tableName)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference(tableName);
await table.CreateIfNotExistsAsync();
}
}
}

关于c# - CloudTableClient.CreateCloudTableClient 抛出 System.IO.FileNotFoundException 类型的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50814752/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com