System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
Ticket Hash: 7d0a40d1ddc25eafde222fb7400a42beeb42c91f
Title: I get an error when I use the ToListAsync of EF 6.1.3
Status: Closed Type: Incident
Severity: Important Priority: Medium
Subsystem: LINQ Resolution: External
Last Modified: 2016-01-14 17:37:48
Version Found In: 1.0.99.0
User Comments:
anonymous added on 2016-01-07 18:14:21: (text/x-fossil-plain)
I have a repository that has a method that calls the method ToListAsync of EF, however if I use the ToList, I get and warning that says that the async methods will run sync, but the application works fine.

So my doubt is how to use the async methods of EF with Sqlite.

The methods is this:

public async Task<List<MyType>> getRowsAsync(Params param)
{
    return await miDBContext.MyType
        .Include(x => x.MyType2.MyType3)
        .ToListAsync();
}

Thanks.

mistachkin added on 2016-01-08 00:22:50: (text/x-fossil-plain)
What is the text of the error message?  Is the error seen while compiling or at
runtime?

anonymous added on 2016-01-09 11:38:42: (text/x-fossil-plain)
The message that I get is: the conversion is not valid.

The stack trace is:

"   en System.Data.Common.DbDataReader.GetFieldValue[T](Int32 ordinal)\r\n   en System.Data.Common.DbDataReader.GetFieldValueAsync[T](Int32 ordinal, CancellationToken cancellationToken)\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Data.Entity.Core.Objects.Internal.ShapedBufferedDataRecord.<ReadIntAsync>d__25.MoveNext()\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n   en System.Data.Entity.Core.Objects.Internal.ShapedBufferedDataRecord.<InitializeAsync>d__4.MoveNext()\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Data.Entity.Core.Objects.Internal.BufferedDataReader.<InitializeAsync>d__0.MoveNext()\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.<ExecuteAsync>d__0`1.MoveNext()\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Data.Entity.Core.Objects.ObjectContext.<ExecuteInTransactionAsync>d__3b`1.MoveNext()\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Data.Entity.Core.Objects.ObjectQuery`1.<GetResultsAsync>d__12.MoveNext()\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Data.Entity.Core.Objects.ObjectQuery`1.<<System.Data.Entity.Infrastructure.IDbAsyncEnumerable<T>.GetAsyncEnumerator>b__1>d__2.MoveNext()\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Data.Entity.Internal.LazyAsyncEnumerator`1.<MoveNextAsync>d__1.MoveNext()\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.<ForEachAsync>d__5`1.MoveNext()\r\n--- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---\r\n   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   en System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   en Repositorio.RepositorioSQLiteEF6.<buscarVideosAsync>d__12.MoveNext() en D:\\proyectos\\RepositorioSQLiteEF6.cs:línea 288"



I have tried this code:

dynamic dummy = await miDBContext.MyType
                            .Include(v => v.MyType2.MyType3)
                            .ToListAsync();

                        return dummy;

I have tried to use a dynamic object to store anything that I get from ToListAsync(), but the problem is the same.

Perhaps this information could be useful:

Source: {T GetFieldValue[T](Int32)}
Data: {System.Collections.ListDictionaryInternal}
TargetSite: {T GetFieldValue[T](Int32)}
CompareGenres: 'compareGenres' threw an exception of type 'System.NullReferenceException'

anonymous added on 2016-01-09 11:53:48: (text/x-fossil-plain)
Ok, the problem is in the include. If I don't do the include, then it works.

The odd thing is that when I use the sync method ToList() it works with the include too.

The three tables:


CREATE TABLE [Videos] (
  [IDContenido] INTEGER NOT NULL PRIMARY KEY CONSTRAINT [FK_Videos_IDContenido] REFERENCES [Contenidos]([IDContenido]) ON DELETE CASCADE ON UPDATE CASCADE, 
  [IDTipoVideo] INTEGER NOT NULL CONSTRAINT [FK_Videos_IDTipoVideo] REFERENCES [TiposVideos]([IDTipoVideo]), 
  [Duracion] INTEGER);

CREATE INDEX [IX_Videos_IDTipoVideo] ON [Videos] ([IDTipoVideo]);





CREATE TABLE [Contenidos] (
  [IDContenido] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
  [Titulo] VARCHAR NOT NULL, 
  [TituloOriginal] VARCHAR, 
  [IDTipoContenido] INTEGER NOT NULL CONSTRAINT [FK_Contenidos_IDTipoContenido] REFERENCES [TiposContenidos]([IDTipoContenido]), 
  [Observaciones] VARCHAR, 
  [Año] INTEGER, 
  [Favorito] BOOL, 
  [Pendiente] BOOL);

CREATE INDEX [IX_Contenidos_IDTipoContenido] ON [Contenidos] ([IDTipoContenido]);



CREATE TABLE [GenerosContenidos] (
  [IDGenero] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
  [Genero] VARCHAR, 
  [IDTipoContenido] INTEGER NOT NULL CONSTRAINT [FK_GenerosVideos_IDTipoContenido] REFERENCES [TiposContenidos]([IDTipoContenido]));

CREATE UNIQUE INDEX [IX_GenerosVideos_GeneroVideo] ON [GenerosContenidos] ([Genero]);

CREATE INDEX [IX_GenerosVideos_IDTipoContenido] ON [GenerosContenidos] ([IDTipoContenido]);



And the real quiery is this:

dynamic dummy = await miDBContext.Videos
                            .Include(v => v.Contenidos.GenerosContenidos)
                            .ToListAsync();

anonymous added on 2016-01-11 16:13:19: (text/x-fossil-plain)
I have done more tests and I note that the problem is when I use WCF to send the results of the query from EF to the client. So it seems that the problem is with WCF.

The odd thing is that using the sync method with WCF works and when I use the async method I get the error. But I don't know if the problem is with WCF ot with the ToListAsync() method.