Method not found: 'System.Threading.Tasks.Task`1<Microsoft.Azure.Cosmos.Serialization.HybridRow.Result>

1.3k views Asked by At

Getting below error when trying to insert into CosmosDb. Document is being inserted but throwing this error. I'm using .net core 5.0, Microsoft.Azure.Cosmos 3.17.0. Please advise.

Method not found: 'System.Threading.Tasks.Task1<Microsoft.Azure.Cosmos.Serialization.HybridRow.Result> Microsoft.Azure.Cosmos.Serialization.HybridRow.RecordIO.RecordIOStream.ReadRecordIOAsync(System.IO.Stream, System.Func2<System.ReadOnlyMemory1<Byte>,Microsoft.Azure.Cosmos.Serialization.HybridRow.Result>, System.Func2<System.ReadOnlyMemory1<Byte>,Microsoft.Azure.Cosmos.Serialization.HybridRow.Result>, 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;
            }
        }
2

There are 2 answers

0
Matias Quaranta On

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

Repeating what was stated in the comments for future reference: This is often related to DLL mismatching (older DLL for one or more dependencies).

It could be the project contains references to other projects with older versions of the SDK, in which case, make sure all the versions match.

It could also be an issue with your deployment process, maybe when the deployment happens, some DLLs are not getting overwritten, in which case, always make sure you are cleaning the /bin folder or updating all files with newer versions (some deployment processes might not update DLLs or the DLLs might be locked and currently in use).

0
Ruben Mamo On

I had the same issue with your same version, however, it turned out that the problem was caused by the dependencies installed in the CosmosDb Health Check from https://github.com/xabaril/AspNetCore.Diagnostics.HealthChecks I had version 5.03 of the health check and 3.17.1 of the Cosmos library and I was getting those errors.

When I removed the health check the issue went away.