fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
570 stars 144 forks source link

... Unable to load one or more of the requested types ... #665

Closed travis-leith closed 8 months ago

travis-leith commented 4 years ago

Description

I am trying to get a basic demo working against MariaDB10 using MySqlConnector but can't get it to compile. The advice given in this related issue doesn't seem to help.

Repro steps

Create a project with the following code

open FSharp.Data.Sql

[<Literal>]
let connString  = "Server=***;Database=market_data;Uid=***;Pwd=***;Port=3307;AllowLoadLocalInfile=true"

[<Literal>]
let dbVendor    = Common.DatabaseProviderTypes.MYSQL

[<Literal>]
let connString2 = @"Server=DESKTOP-7N1E2PV;Database=factor_investments;User Id=Travis;Password=welcome123;"

[<Literal>]
let resPath = __SOURCE_DIRECTORY__ + "/DLLs"

[<Literal>]
let useOptTypes = true

type sql = 
    SqlDataProvider<
        Common.DatabaseProviderTypes.MYSQL,
        connString,
        ResolutionPath = resPath,
        UseOptionTypes = useOptTypes>

//let ctx = sql.GetDataContext()

[<EntryPoint>]
let main argv =
    printfn "Hello World from F#!"
    0 // return an integer exit code

and the following libraries

<ItemGroup>
    <PackageReference Include="MySqlConnector" Version="0.61.0" />
    <PackageReference Include="SQLProvider" Version="1.1.76" />
    <PackageReference Include="System.Console" Version="4.3.1" />
    <PackageReference Include="System.Data.Common" Version="4.3.0" />
    <PackageReference Include="System.Reflection" Version="4.3.0" />
    <PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
    <PackageReference Include="System.Runtime" Version="4.3.1" />
    <PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
    <PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
    <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.3" />
  </ItemGroup>

Place the MySqlConnector.dll in the 'DLLs' folder and try to build.

Expected behavior

Successful build

Actual behavior

The following compile error is given

Severity    Code    Description Project File    Line    Suppression State
Error   FS3033  The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Details: 
Could not load type 'System.ICloneable' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load type 'System.Data.Common.DbCommandBuilder' from assembly 'System.Data.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load type 'System.Data.Common.DbDataAdapter' from assembly 'System.Data.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load type 'System.Data.Common.RowUpdatingEventArgs' from assembly 'System.Data.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load type 'System.Data.Common.RowUpdatedEventArgs' from assembly 'System.Data.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load file or assembly 'System.Runtime.Extensions, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Net.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load type 'System.ReadOnlyMemory`1' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load type 'System.IO.Stream' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load type 'System.ReadOnlySpan`1' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load file or assembly 'System.Memory, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Transactions.Local, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
Could not load type 'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load type 'System.Memory`1' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.    Analytics   xxx\Program.fs  20  Active

Related information

Thorium commented 4 years ago

I think with type providers you should use compiletime the full .NET framework dll and runtime the Core dll.

Thorium commented 4 years ago

See: https://github.com/fsprojects/SQLProvider/tree/master/tests/SqlProvider.Core.Tests/MySql

travis-leith commented 4 years ago

@Thorium the instructions given in your link almost worked; they were able to remove errors visible in VS, but upon building I get the following error The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.Details: Could not load file or assembly 'System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.Could not load file or assembly 'System.Threading.Tasks.Extensions,...

So I added the package System.Memory and copied the dll to the libraries folder, then upon building I get

The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe,...

I have tried adding the packing System.Runtime.CompilerServices.Unsafe and copying the dll but no change in error.

Also, the test project in this repo does not work for me. Trying to build results in

Severity    Code    Description Project File    Line    Suppression State
Error   FS3033  The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Exception has been thrown by the target of an invocation.    SqlProvider.Core.Tests  C:\repos\New folder\SQLProvider\tests\SqlProvider.Core.Tests\MySql\Program.fs   30  Active
Thorium commented 4 years ago

Hi, I upgraded few system references, to SQLProvider 1.1.79, hope that helped.

Thorium commented 8 months ago

This is fixed