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

DuckDBConnection.Open Throwing 'The type initializer for 'DuckDB.NET.Data.DuckDBConnectionStringBuilder' threw an exception.' #241

Closed
TheLastArchive opened this issue Dec 13, 2024 · 11 comments

Comments

@TheLastArchive
Copy link

I've tried with the two different NuGet packages 'DuckDB.NET.Data.Full' and 'DuckDB.NET.Bindings.Full'

When I attempt to open the DuckDB connection like so:
using (var connection = new DuckDBConnection("DataSource=:memory:")) { connection.Open(); ... }

I get the exception listed in the title:

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

I've followed along in the debugger and here is where everything goes wrong in DuckDBConnection.cs

internal DuckDBConnectionString ParsedConnection => parsedConnection ??= DuckDBConnectionStringBuilder.Parse(ConnectionString);

ConnectionString is set to DataSource=:memory:

I tried following a similar issue that's been closed out and didn't really resolve my issue. Is there any additional setup that I may be missing? I followed the documentation to the best of my ability .

@Giorgi
Copy link
Owner

Giorgi commented Dec 13, 2024

What type of project are you building? Is it a Blazor app by any chance?

@TheLastArchive
Copy link
Author

@Giorgi Apologies for the late reply, but no it's not a Blazor app. I did read through #169

@Giorgi
Copy link
Owner

Giorgi commented Dec 16, 2024

Can you post the full exception? Including the InnerException.

@TheLastArchive
Copy link
Author

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

Exception StackTrace StackTrace = " at DuckDB.NET.Data.DuckDBConnectionStringBuilder.Parse(String connectionString) in //DuckDB.NET.Data/DuckDBConnectionStringBuilder.cs:line 68\r\n at DuckDB.NET.Data.DuckDBConnection.get_ParsedConnection() in //DuckDB.NET.Data/DuckDBConnection.cs:lin...

Exception Source = "DuckDB.NET.Data"

InnerException Message= {"Unable to load DLL 'duckdb': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"}

InnerException StackTrace = " at DuckDB.NET.Native.NativeMethods.Configuration.DuckDBConfigCount()\r\n at DuckDB.NET.Data.DuckDBConnectionStringBuilder..cctor() in /_/DuckDB.NET.Data/DuckDBConnectionStringBuilder.cs:line 25"

InnerException Source = "DuckDB.NET.Bindings"

It not being able to find the .dll is odd.

@Giorgi
Copy link
Owner

Giorgi commented Dec 16, 2024

Which version of .NET are you targeting? Did you download duckdb.dll from the official website by any chance? There were some similar issues posted in discord channel, did you check them?

@TheLastArchive
Copy link
Author

TheLastArchive commented Dec 16, 2024

TargetFrameworkVersion > v4.8

Here's the references in my .csproj:

<Reference Include="DuckDB.NET.Bindings, Version=1.1.3.0, Culture=neutral, PublicKeyToken=1d0aa5325e915c3b, processorArchitecture=MSIL">
  <HintPath>..\packages\DuckDB.NET.Bindings.Full.1.1.3\lib\netstandard2.0\DuckDB.NET.Bindings.dll</HintPath>
</Reference>
<Reference Include="DuckDB.NET.Data, Version=1.1.3.0, Culture=neutral, PublicKeyToken=1d0aa5325e915c3b, processorArchitecture=MSIL">
  <HintPath>..\packages\DuckDB.NET.Data.Full.1.1.3\lib\netstandard2.0\DuckDB.NET.Data.dll</HintPath>
</Reference>

I downloaded the DuckDB-JDBC from Maven Repository a while ago for work on another project, but that would have been separate from the current .NET project.

@Giorgi
Copy link
Owner

Giorgi commented Dec 16, 2024

DuckDB.NET.Data and DuckDB.NET.Bindings do not contain the native duckdb.dll. You must download it manually from the official website and put it in the bin folder.

Make sure that your project is x64 and download the correct duckdb.dll - there are x64 and arm builds for Windows.

@TheLastArchive
Copy link
Author

Apologies for the late response.

I checked the official site and I don't see any downloads for a dll, would it be included in either the cli after I run the exe, or will I need to download the ODBC?

@Giorgi
Copy link
Owner

Giorgi commented Dec 16, 2024

You can download it from https://duckdb.org/docs/installation/?version=stable&environment=cplusplus&platform=win&download_method=direct&architecture=x86_64 or install DuckDB.NET.Data.Full and copy duckdb.dll manually from the runtimes folder.

@TheLastArchive
Copy link
Author

Thank you. Unfortunately it seems that the project's platform target is x86, the product is several years old so I doubt switching to x64 would be feasible anytime soon. It seems that DuckDB only supports x64 so I may be out of luck.

@Giorgi
Copy link
Owner

Giorgi commented Dec 17, 2024

That's right, DuckDB doesn't support x86.

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

No branches or pull requests

2 participants