Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DuckDBConnectionStringBuilder threw an exception #180

Closed
Tor-Storli opened this issue Apr 3, 2024 · 4 comments
Closed

DuckDBConnectionStringBuilder threw an exception #180

Tor-Storli opened this issue Apr 3, 2024 · 4 comments
Labels

Comments

@Tor-Storli
Copy link

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
Copy link
Owner

Giorgi commented Apr 3, 2024

'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 #169

@Tor-Storli
Copy link
Author

Ok! Thanks for the quick response! :)

@Giorgi
Copy link
Owner

Giorgi commented Apr 6, 2024

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 Giorgi added the wasm label Apr 9, 2024
@Giorgi
Copy link
Owner

Giorgi commented Apr 14, 2024

Closing this, Blazor support is tracked in #169

@Giorgi Giorgi closed this as completed Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants