SQLProvider
SQLProvider copied to clipboard
Unhandled Exception: System.TypeLoadException: Could not load type 'System.Data.SqlClient.SqlConnection'
Description
I'm getting this error when I execute "dotnet run"
Unhandled Exception: System.TypeLoadException: Could not load type 'System.Data.SqlClient.SqlConnection' from assembly 'System.Data.SqlClient, Version=4.2.0.0, Culture=neutra
l, PublicKeyToken=b03f5f7f11d50a3a'.
at FSharp.Data.Sql.Providers.MSSqlServerProvider.FSharp-Data-Sql-Common-ISqlProvider-CreateConnection(String connectionString)
at <StartupCode$FSharp-Data-SqlProvider>[email protected](String typeName)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at FSharp.Data.Sql.Runtime.SqlDataContext..ctor(String typeName, String connectionString, DatabaseProviderTypes providerType, String resolutionPath, String[] referencedAss
emblies, String runtimeAssembly, String owner, CaseSensitivityChange caseSensitivity, String tableNames, OdbcQuoteCharacter odbcquote, SQLiteLibrary sqliteLibrary, Transactio
nOptions transactionOptions, FSharpOption`1 commandTimeout)
at Program.main(String[] argv) in /Users/Marvs/source/fsharp/FSAccountGo/src/AccountGoCLI/Program.fs:line 18
But I can successfully build the solution/project "dotnet build".
Here is my .csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<FscToolPath>/Library/Frameworks/Mono.framework/Versions/Current/bin</FscToolPath>
<FscToolExe>fsharpc</FscToolExe>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SQLProvider" Version="1.1.52" />
</ItemGroup>
<Target Name="BeforeBuild">
<Copy SourceFiles="/Users/Marvs/.nuget/packages/sqlprovider/1.1.52/lib/netstandard2.0/" DestinationFolder="$(OutDir)" />
</Target>
</Project>
I'm not sure if I need this line, but with without it same output.
<Target Name="BeforeBuild">
<Copy SourceFiles="/Users/Marvs/.nuget/packages/sqlprovider/1.1.52/lib/netstandard2.0/" DestinationFolder="$(OutDir)" />
</Target>
But these lines seems important as I am getting other errors without it. Why I need this? This looks my project can't be run on windows.
<FscToolPath>/Library/Frameworks/Mono.framework/Versions/Current/bin</FscToolPath>
<FscToolExe>fsharpc</FscToolExe>
Mono is already in my PATH
PATH=/Users/Marvs/.cargo/bin:~/Library/Python/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/Marvs/source/go/bin:/Users/Marvs/bin:/Library/Frameworks/Mono.framework/Versions/Current/bin/
Repro steps
Please provide the steps required to reproduce the problem
-
Create a solution and F# console project
-
Add SQLProvider package to F# console project. "dotnet add package SQLProvider --version 1.1.52"
-
Add these lines
open FSharp.Data.Sql
let [<Literal>] dbVendor = Common.DatabaseProviderTypes.MSSQLSERVER
let [<Literal>] connString = "Server=localhost;Database=accountgo;User Id=sa;Password=Str0ngPassword;"
let [<Literal>] indivAmount = 1000
let [<Literal>] useOptTypes = true
type sql =
SqlDataProvider<
DatabaseVendor = dbVendor,
ConnectionString = connString,
IndividualsAmount = indivAmount,
UseOptionTypes = useOptTypes>
[<EntryPoint>]
let main argv =
let ctx = sql.GetDataContext()
ctx.Dbo.Company.Individuals.``1`` |> printf "%A"
0 // return an integer exit code
- Build and run "dotnet build", "dotnet run"
Expected behavior
NO Unhandled Exception: System.TypeLoadException: Could not load type
Actual behavior
Unhandled Exception
Known workarounds
Please provide a description of any known workarounds.
Related information
- MS SQL
- MacOS Mojave v10.14
- Branch
- Mono version 5.12.0 .NET Core SDK (reflecting any global.json): Version: 2.1.401 Commit: 91b1c13032
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.14
OS Platform: Darwin
RID: osx-x64
Base Path: /usr/local/share/dotnet/sdk/2.1.401/
Host (useful for support):
Version: 2.1.3
Commit: 124038c13e
.NET Core SDKs installed:
2.0.0 [/usr/local/share/dotnet/sdk]
2.1.4 [/usr/local/share/dotnet/sdk]
2.1.401 [/usr/local/share/dotnet/sdk]
- Performance information, links to performance testing scripts
You need a post build step to ensure the needed dll is present at runtime.
It took me a little bit to get it working properly in my project, but looking at issue #462 was helpful. I think the issue(s) I had were path related (self inflicted), but I just kept tweaking it until I got the needed dll to show up in my build artifacts.
Also, in case you haven't seen it already, this is mentioned in the docs here. http://fsprojects.github.io/SQLProvider/core/netstandard.html#Microsoft-Sql-Server
I saw something like this with SQLProvider 1.1.52, I reverted to 1.1.49 which fixed the issue.
Could you try that version? see if we are having the same problem? I'm using Postgres, not MSSQL.
Try adding references to System.Data and System.Data.SqlClient
I am having this same issue with a similar Runtime Environment as the OP, however I am using Paket.
EDIT: Actually I am receiving this error when trying to build my app
@Thorium Is this an issue with system.data.sqlclinet? If so should we be putting an issue in with that repo
I'm not sure how well System.Data.SqlClient supports .NET Core 3.1. However, this can also be SQLProvider not finding correct dlls when doing reflection loading.
I have only Windows environment near, but this works for me: https://github.com/fsprojects/SQLProvider/issues/645#issuecomment-639163535
@thorium you can get docker for windows and run Linux container builds locally. that is what I'm doing before pushing up to are linux server. Let me know if there is anything I can do to help out
was this resolved? i also got this error from macos in .fsx dotnet6