Giorgi / DuckDB.NET

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

DuckDBConnectionStringBuilder threw an exception #180

Closed Tor-Storli closed 2 months ago

Tor-Storli commented 3 months ago

I used Nuget to add DuckDB.NET.Data.Full (0.10.1.2) to my Blazor WebAssembly project.

I tried this code:
using var duckDBConnection = new DuckDBConnection("DataSource=:memory:"); duckDBConnection.Open();

As well as this code pointing to a local duckDB database:

using var duckDBConnection = new DuckDBConnection("DataSource=stocks.db"); duckDBConnection.Open();

Both methods give me this error on this part of the code: duckDBConnection.Open();

'The type initializer for 'DuckDB.NET.Data.DuckDBConnectionStringBuilder' threw an exception.'

Is there anything I need to add or change to fix this issue. I tried a try{} catch{} to get more info:

   catch(Exception e) {
       // Print the full exception details, including inner exceptions
       Console.WriteLine($"Error: {e.Message}");
       if (e.InnerException != null)
       {
           Console.WriteLine($"Inner Exception: {e.InnerException.Message}");
       }
   }

But I was unable to get more info about the problem. Any help is appreciated.

Giorgi commented 3 months ago

'The type initializer for 'DuckDB.NET.Data.DuckDBConnectionStringBuilder' threw an exception.' means that the exception happened in the static constructor of DuckDBConnectionStringBuilder This is probably because of DuckDBConfigCount call to the DuckDB native library.

Even if you comment out that code and remove the static constructor completely, you will probably only delay the error. I'm not sure why that call is failing, but probably every native method call will fail because of the same reason. You could debug the library to see what exception is thrown when calling the native methods.

By the way, using the library from Blazor isn't supported yet. See https://github.com/Giorgi/DuckDB.NET/issues/169

Tor-Storli commented 3 months ago

Ok! Thanks for the quick response! :)

Giorgi commented 2 months ago

The full exceptions is

Unhandled exception rendering component: The type initializer for 'DuckDB.NET.Data.DuckDBConnectionStringBuilder' threw an exception.
System.TypeInitializationException: The type initializer for 'DuckDB.NET.Data.DuckDBConnectionStringBuilder' threw an exception.
 ---> System.DllNotFoundException: duckdb
   at DuckDB.NET.Data.DuckDBConnectionStringBuilder..cctor() in \src\DuckDB.NET\DuckDB.NET.Data\DuckDBConnectionStringBuilder.cs:line 25
   --- End of inner exception stack trace ---
   at DuckDB.NET.Data.DuckDBConnection.get_ParsedConnection() in \src\DuckDB.NET\DuckDB.NET.Data\DuckDBConnection.cs:line 29
   at DuckDB.NET.Data.DuckDBConnection.Open() in \src\DuckDB.NET\DuckDB.NET.Data\DuckDBConnection.cs:line 103
Giorgi commented 2 months ago

Closing this, Blazor support is tracked in #169