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
579 stars 146 forks source link

Upgrading from 1.1.11: IDbConnection not found in reference assembly set #490

Open cmeeren opened 6 years ago

cmeeren commented 6 years ago

I tried to upgrade from 1.1.11 to 1.1.20, but compilation now gives the the following error:

error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: The type 'System.Data.IDbConnection' utilized by a type provider was not found in reference assembly set '[|ctxt assembly FSharp.Data.SqlProvider, Version=1.1.20.0, Culture=neutral; ctxt assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089; ctxt assembly FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; ctxt assembly System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089; ctxt assembly System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089; ctxt assembly System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089|]'. You may be referencing a portable profile which contains fewer types than those needed by the type provider you are using.

This happens when trying to update to any version >= 1.1.12. Reverting to 1.1.11 fixes the issue.

The project in question is .NET Framework 4.7 class library. The latest FSharp.Core is installed via nuget.

Any idea what might be wrong or how I can debug this?

Thorium commented 6 years ago

Yes, it seems your project referenced the netstandard dll and not net451 dll like earlier. Both are now in the nuget package. Are you using Nuget or Paket or what...?

cmeeren commented 6 years ago

Nuget in VS2017 15.4.2.

Thorium commented 6 years ago

I tried this initially and in my project it still took net451, so it would be interesting to know why this has happened.

cmeeren commented 6 years ago

I'll happily provide any details you want (except the full project; it's a work project).

Thorium commented 6 years ago

I'm trying to reproduce this... Do you use the old or new fsharp project structure?

I expect the problem is this: Since 1.1.12 version, SQLProvider Nuget-package has two possible libraries:

lib\net451\FSharp.Data.SqlProvider.dll
lib\netstandard2.0\FSharp.Data.SqlProvider.dll

The first one is similar to 1.1.11 version, using the .NET Framework. The later has .NET Core support, but it needs a lot of framework-assemblies. So in your case the reference should be the first one.

System.Data.IDbConnection should be present in the .NET Framework 4.7 Do you have a reference to System.Data.dll in your project?

This site tells what reference dll should Nuget select, and as you see, by default it should choose the net451 for net47: http://nugettoolsdev.azurewebsites.net/4.2.0/get-nearest-framework?project=net47&package=net451%0D%0Anetstandard2.0%0D%0A%0D%0A

cmeeren commented 6 years ago

I'm using the old project format. AFAIK the new one isn't supported in VS 15.4, which I'm using. (If there is a way to use the new format and/or .NET Standard 2.0, I'm very interested in that, but AFAIK that's not supported until 15.5.)

My fsproj contains no reference to System.Data. Here are all my references:

<ItemGroup>
  <Reference Include="FSharp.Data.SqlProvider">
    <HintPath>..\..\..\..\..\..\lib\NuGet\SQLProvider.1.1.11\lib\FSharp.Data.SqlProvider.dll</HintPath>
  </Reference>
  <Reference Include="mscorlib" />
  <Reference Include="System" />
  <Reference Include="System.Core" />
  <Reference Include="System.Numerics" />
</ItemGroup>

Adding a reference to System.Data fixes the problem:

  <Reference Include="FSharp.Data.SqlProvider">
    <HintPath>..\..\..\..\..\..\lib\NuGet\SQLProvider.1.1.20\lib\net451\FSharp.Data.SqlProvider.dll</HintPath>
  </Reference>
  <Reference Include="mscorlib" />
  <Reference Include="System" />
  <Reference Include="System.Core" />
  <Reference Include="System.Numerics" />
  <Reference Include="System.Data" />
</ItemGroup>

Is adding System.Data something that needs to be done manually?

Thorium commented 6 years ago

We are using System.Data manually, however I don't know why it has become a requirement since 1.1.11 as the original solution/project files are not modified.

hoetz commented 6 years ago

I just upgraded from 1.1.17 to 1.1.23 and had the same issue. Adding System.Data ref fixed it.

mushishi78 commented 5 years ago

Adding System.Data manually still seems to need to be done

moviezhou commented 4 years ago

Many thanks for this solution @Thorium. Adding System.Data reference fixed.