Skip to content

Unhandled Exception: System.TypeLoadException: Could not load type 'System.Data.SqlClient.SqlConnection' #580

Open
@mvperez

Description

@mvperez

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>.$SqlRuntime.DataContext.-ctor@37-54.Invoke(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

  1. Create a solution and F# console project

  2. Add SQLProvider package to F# console project. "dotnet add package SQLProvider --version 1.1.52"

  3. 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
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NET Core reference assembly loadingNot a bug, but a question about usability with .NET Core. Right dlls are not in ResolutionPath.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions