找不到方法:'System.Threading.Tasks.Task`1<Microsoft.Azure.Cosmos.Serialization.HybridRow.Result>

问题描述

尝试插入 CosmosDb 时出现以下错误。正在插入文档但抛出此错误。我使用的是 .net core 5.0,Microsoft.Azure.Cosmos 3.17.0。请指教。

找不到方法:'System.Threading.Tasks.Task1<Microsoft.Azure.Cosmos.Serialization.HybridRow.Result> Microsoft.Azure.Cosmos.Serialization.HybridRow.Recordio.RecordioStream.ReadRecordioAsync(System.IO.Stream,System.Func21<Byte>,Microsoft.Azure.Cosmos.Serialization.HybridRow.Result>,System.Func21<Byte>,Microsoft.Azure.Cosmos.Serialization.HybridRow.MemorySpanResizer1)'

protected virtual CosmosClient _cosmosClient
    {
        get
        {
            var options = new CosmosClientOptions
            {
                SerializerOptions = new CosmosSerializationoptions
                {
                    IgnoreNullValues = true,PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase
                },AllowBulkExecution = true
            };

            return new CosmosClient(_connectionString,options);
        }
    }

    protected Container _cosmosContainer
    {
        get => _cosmosClient.GetContainer(_databaseId,_containerId);
    }

protected async Task<T> CreateItemAsync<T>(string id,T model,PartitionKey partitionKey)
        {
            try
            {
                return await _cosmosContainer.CreateItemAsync(model,partitionKey);
            }
            catch (CosmosException ex)
            {
                LogCosmosDbError(ex);

                throw;
            }
        }

解决方法

参考:https://github.com/Azure/azure-cosmos-dotnet-v3/issues/2292#issuecomment-796104041

重复评论中的内容以供将来参考:这通常与 DLL 不匹配(一个或多个依赖项的旧 DLL)有关。

可能是该项目包含对使用旧版 SDK 的其他项目的引用,在这种情况下,请确保所有版本都匹配。

这也可能是您的部署过程的问题,也许在部署发生时,某些 DLL 没有被覆盖,在这种情况下,请始终确保您正在清理 /bin 文件夹或使用更新的文件更新所有文件版本(某些部署过程可能不会更新 DLL,或者 DLL 可能被锁定并且当前正在使用中)。

,

我在您的同一版本中遇到了同样的问题,但是,结果证明问题是由 https://github.com/xabaril/AspNetCore.Diagnostics.HealthChecks 的 CosmosDb 健康检查中安装的依赖项引起的 我有 5.03 版的健康检查和 3.17.1的 Cosmos 库,我收到了这些错误。

当我删除运行状况检查时,问题就消失了。