View.ViewNotFoundException when run ViewQueryAsync in .NET.Client 3.4.1

Hi, After upgrade couchbase .NET SDK
I try View Query functionality and try to use ViewQueryAsync instead explisit create connection.
I use such code, and it’s raise exception ViewNotFoundException .

        public IEnumerable<TResult> QueryView<TResult, TKey>(IEnumerable<TKey> keys, string viewName, string designDoc =)
        {
            var keyObjects = keys.ToArray() as object[];

            try
            {
                return _bucket.ViewQueryAsync<TKey, TResult>(designDoc, viewName, options => { options.Keys(keyObjects); }).ConfigureAwait(false).GetAwaiter().GetResult().Rows.Select(r => r.Value).ToListAsync().Result;
            }
            catch (Exception e)
            {
                 throw;
            }
            
            return Array.Empty<TResult>();
        }

Old version run with out exception .

        public IEnumerable<TResult> QueryView<TResult, TKey>(IEnumerable<TKey> keys, string viewName, string designDoc)
        {
            var query = new ViewQuery().From(designDoc, viewName).Stale(StaleState.False);

            var keyObjects = keys.ToArray() as object[];

            try
            {
                return this._bucket.Query<TResult>(query).Values;
            }
            catch (Exception e)
            {
                throw;
            }
        }

A couple of things to try that may help.

  1. Make sure that you cluster.WaitUntilReadyAsync() on startup to ensure everything is ready to use before your application is healthy and tries to use the cluster.
  2. You should, generally speaking, never use .Result or .Wait() on a task unless you really know what you’re doing. This can create all kinds of weird side effects. You should make the method asynchronous instead. If that is not an option due to the scope of work, you can try this library we use to gradually introduce async: GitHub - CenterEdge/CenterEdge.Async: When you gotta, you gotta. There are other similar implementations of that pattern out there, though I think this one is the best (I’m biased though).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.