Giorgi / DuckDB.NET

Bindings and ADO.NET Provider for DuckDB
https://duckdb.net
MIT License
356 stars 62 forks source link

Object reference not set to an instance of an object #25

Closed maikgroenewegen closed 2 years ago

maikgroenewegen commented 2 years ago

Description

Running on M1 Mac with .NET6 (6.0.203) using self build libduckdb.dylib (arm64) from recent master. Samples project fails at line 43: PrintQueryResults(reader);

The actual error happens in DuckDBNativeObjects.cs line 93: var column = Marshal.PtrToStructure(columns + Marshal.SizeOf() * i); (a The error message is:

Exception has occurred: CLR/System.NullReferenceException An unhandled exception of type 'System.NullReferenceException' occurred in System.Private.CoreLib.dll: 'Object reference not set to an instance of an object.' at System.Runtime.CompilerServices.CastHelpers.Unbox(Void* toTypeHnd, Object obj) at System.Runtime.InteropServices.Marshal.PtrToStructure[T](IntPtr ptr)

Earlier actions (creating table, inserting data) seem to be successful when I check the file.db database using DuckDB CLI.

Giorgi commented 2 years ago

Looks like the latest duckdb has some breaking changes for querying data: duckdb.h

You should be able to make it work if you compile it with DUCKDB_API_VERSION < DUCKDB_API_0_3_2 until I update the library

Giorgi commented 2 years ago

Alternatively, you can compile one of the earlier releases that don't have that breaking change.

maikgroenewegen commented 2 years ago

Compiled an older version (0.3.1) of DuckDB and that seems to work with the current version of DuckDB.NET. I do encounter an other error in Dapper when running line 45:

var results = duckDBConnection.Query<FooBar>("SELECT foo, bar FROM integers");

An unhandled exception of type 'System.NullReferenceException' occurred in Dapper.dll: 'Object reference not set to an instance of an object.' but I can leave that be for now.

Giorgi commented 2 years ago

Can you post the full stack trace of that exception?

maikgroenewegen commented 2 years ago

This is stack trace. I'm using Dapper version 2.0.123

Exception has occurred: CLR/System.NullReferenceException
An unhandled exception of type 'System.NullReferenceException' occurred in Dapper.dll: 'Object reference not set to an instance of an object.'
   at Dapper.SqlMapper.<QueryImpl>d__140`1.<>m__Finally1() in /_/Dapper/SqlMapper.cs:line 1137
   at Dapper.SqlMapper.<QueryImpl>d__140`1.MoveNext() in /_/Dapper/SqlMapper.cs:line 1123
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 734
Giorgi commented 2 years ago

This is now implemented in release 0.4.0