Async error

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
KW
Posts: 135
Joined: Tue 19 Feb 2008 19:12

Async error

Post by KW » Thu 09 Feb 2017 00:22

I'm trying to run this code in a Web Controller using the Test Database

Code: Select all

.

 [ResponseType(typeof(IEnumerable<Order>))]
        public async Task<IHttpActionResult> GetOrders()
        {
            try
            {
                IEnumerable<Order> entities = await _dbContext.Orders
                    // TODO: Add Includes for reference and/or collection properties
                    .ToListAsync();
                return Ok(entities);
            }
            catch
            {
                return null;
            }
        }
It always throws an exception "object reference not set to an instance of an object"

at System.Data.Entity.Core.EntityKey.AddHashValue(Int32 hashCode, Object keyValue)
at System.Data.Entity.Core.EntityKey.GetHashCode()
at System.Collections.Generic.GenericEqualityComparer`1.GetHashCode(T obj)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at System.Data.Entity.Core.Objects.ObjectStateManager.TryGetEntityEntry(EntityKey key, EntityEntry& entry)
at System.Data.Entity.Core.Objects.ObjectStateManager.FindEntityEntry(EntityKey key)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
at lambda_method(Closure , Shaper )
at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.<MoveNextAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.<ForEachAsync>d__5`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at TrackableWebApi1.WebApi.Controllers.OrderController.<GetOrders>d__0.MoveNext() in c:\Users\kylel\OneDrive\Documents\Visual Studio 2013\Projects\TrackableWebApi1\TrackableWebApi1\TrackableWebApi1.WebApi\Controllers\OrderController.cs:line 28


Keep in mind that this code works correctly:

Code: Select all

 // GET api/Order/5
        [ResponseType(typeof(Order))]
        public async Task<IHttpActionResult> GetOrder(int id)
        {
            Order entity = await _dbContext.Orders
                // TODO: Add Includes for reference and/or collection properties
                .SingleOrDefaultAsync(e => e.OrderID == id);

            if (entity == null)
            {
                return NotFound();
            }

            return Ok(entity);
        }

In the "public async Task<IHttpActionResult> GetOrders()" if I hover over _dbcontext and try and to expand orders it gives an error "command out of sync". However, if I do the exact same thing in "public async Task<IHttpActionResult> GetOrder(int id)" it expand the orders correctly.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Async error

Post by Shalex » Fri 10 Feb 2017 16:05


KW
Posts: 135
Joined: Tue 19 Feb 2008 19:12

Re: Async error

Post by KW » Wed 15 Feb 2017 16:40

Yes that corrected the issue.

Post Reply