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

netcoreapp2.0 with Sql Server access fails to compile on Linux #499

Closed
dmitry-a-morozov opened this issue Dec 21, 2017 · 16 comments
Closed

Comments

@dmitry-a-morozov
Copy link
Member

I have netcoreapp2.0 that uses SQLProvider to access Sql Server
It compiles and runs on Windows perfectly.
On Linux build fails with

error FS3053 : The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error : The type provider constructor has thrown an exception: The method or operation is not implemented. [/mnt/c/Users/dmorozov/source/repos/TrySQLProviderWithSqlServer/TrySQLProviderWithSqlServer.fsproj]
FSC : warning FS3005: Referenced assembly '/home/dmorozov/.nuget/packages/sqlprovider/1.1.23/lib/netstandard2.0/FSharp.Data.SqlProvider.dll' has assembly level attribute 'Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute' but no public type provider classes were found [/mnt/c/Users/dmorozov/source/repos/TrySQLProviderWithSqlServer/TrySQLProviderWithSqlServer.fsproj]

F# compiler tooling redirection applied

  <PropertyGroup>
    <IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows>
    <IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
    <IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
  </PropertyGroup>
  <PropertyGroup Condition="'$(IsWindows)' == 'true' AND Exists('C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\fsc.exe')">
    <FscToolPath>C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0</FscToolPath>
    <FscToolExe>fsc.exe</FscToolExe>
  </PropertyGroup>
  <PropertyGroup Condition="'$(IsOSX)' == 'true'  AND Exists('/Library/Frameworks/Mono.framework/Versions/Current/Commands/fsharpc')">
    <FscToolPath>/Library/Frameworks/Mono.framework/Versions/Current/Commands</FscToolPath>
    <FscToolExe>fsharpc</FscToolExe>
  </PropertyGroup>
  <PropertyGroup Condition="'$(IsLinux)' == 'true' AND Exists('/usr/bin/fsharpc')">
    <FscToolPath>/usr/bin</FscToolPath>
    <FscToolExe>fsharpc</FscToolExe>
  </PropertyGroup>
@Thorium
Copy link
Member

Thorium commented Dec 21, 2017

If you clone this repo and run the example in tests core, does it work?

@dmitry-a-morozov
Copy link
Member Author

I didn't run the example project but I would argue this is not going to be good test.
The example has direct reference
https://github.com/fsprojects/SQLProvider/blob/master/tests/SqlProvider.Core.Tests/Postgres/SqlProvider.Core.Tests.fsproj#L55

Which is not how real project with PackageReference will look like.

@Thorium
Copy link
Member

Thorium commented Dec 21, 2017

No, that wont be your compilation result.

That is just compilation time reference.

On Linux you compile the project with Mono, which still produces .Net coreapp dll at runtime.

@Thorium
Copy link
Member

Thorium commented Dec 21, 2017

And yes, that is a hack (not the first one in Linux, thoigh) but I don't know the alternative until Mono will support .Net Standard libraries.

Runtime should work on Linux/Win/Mac no matter what you used for the compilation.

I did run the examples in my Ubuntu and the only hard one is SQLite compilation.

@dmitry-a-morozov
Copy link
Member Author

You lost me a little bit.
Let me re-phrase my question.
If I'll do what is described here
https://medium.com/@dsincl12/f-with-net-core-2-0-4-and-sqlprovider-d8f071119da9
Will this project compile on Linux without additional effort?

@dmitry-a-morozov
Copy link
Member Author

Assuming of course that I'll have FscToolPath for Linux too

@Thorium
Copy link
Member

Thorium commented Dec 21, 2017

No. Currently TypeProviders won't compile on Net Core. They compile on net4xx and Mono but do produce .Net core assemblies if that is your target. So at runtime you need .Net Standard version of SQLProvider but at compilation time you need net4xx version. For Windows this is not an issue because Net4xx is Net Standard compatible.

It's a bit confusing. But start with the example at https://github.com/fsprojects/SQLProvider/blob/master/tests/SqlProvider.Core.Tests/Postgres/

@Thorium
Copy link
Member

Thorium commented Dec 21, 2017

Note that toolpath fsc is actually Mono fsharp.

@nojaf
Copy link

nojaf commented Jan 4, 2018

I'm trying the same thing but with MySql.
So I have a docker container with both aspnetcore and mono installed.
My project contains the workaround as described here.

But when building I get

     1>error FS3053 : The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error : The type provider constructor has thrown an exception: The method or operation is not implemented. [/usr/src/app/src/Teams/Teams.fsproj]
         
     1>FSC : warning FS3005: Referenced assembly '/root/.nuget/packages/sqlprovider/1.1.23/lib/netstandard2.0/FSharp.Data.SqlProvider.dll' has assembly level attribute 'Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute' but no public type provider classes were found
[/usr/src/app/src/Teams/Teams.fsproj]
         The command exited with code 1.

I also added

  <ItemGroup><!-- Mono fix -->
    <Reference Condition="'$(IsWindows)' != 'true'" Include="FSharp.Data.SqlProvider">
      <HintPath>../../packages/SQLProvider/lib/net451/FSharp.Data.SqlProvider.dll</HintPath>
    </Reference>
  </ItemGroup>

but I'm guessing my project still uses the netcore dll of SqlProvider.
I believe I should get the same warning as

/usr/src/app/src/Teams/Teams.fsproj : warning NU1701: Package 'FSharp.Data 2.4.3' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
/usr/src/app/src/Teams/Teams.fsproj : warning NU1701: Package 'Zlib.Portable 1.11.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.

But I'm unable to force this using paket.

@nojaf
Copy link

nojaf commented Jan 4, 2018

I've added framework net451 to my paket.dependencies and my problem got resolved.
nuget SQLProvider 1.1.23 framework: net451

@Thorium
Copy link
Member

Thorium commented Jan 12, 2018

@dmitry-a-morozov do you still have the original problem listed in this issue?

@dmitry-a-morozov
Copy link
Member Author

@Thorium The issue haven't resolved for me.
Am I suppose to add

  <ItemGroup><!-- Mono fix -->
    <Reference Condition="'$(IsWindows)' != 'true'" Include="FSharp.Data.SqlProvider">
      <HintPath>../../packages/SQLProvider/lib/net451/FSharp.Data.SqlProvider.dll</HintPath>
    </Reference>
  </ItemGroup>

to a project that consume the type provider?

@Thorium
Copy link
Member

Thorium commented Jan 13, 2018

Yes.

When I'll have more time, I'll make the instructions. But shortly:
On Linux you compile with dotnet but it calls external (FscToolPath) fsharpc.exe which executes on Mono, and for that reason you need /net451/FSharp.Data.SqlProvider.dll on compilation time.

But on runtime you use dotnet without external compiler, but run directly on .NET Core. So at runtime you need /netstandard2.0/FSharp.Data.SqlProvider.dll

They are both in the NuGet package.

@dmitry-a-morozov
Copy link
Member Author

I don't use paket in my project.
How I do get path to net451 version of FSharp.Data.SqlProvider.dll ?
I thought it's located somewhere in global nuget cache.

Also, how about #499 (comment)
How do I add dependency on net451 without paket?

@Thorium
Copy link
Member

Thorium commented Jan 13, 2018

I think it's at ~/.nuget/packages/SQLProvider/
...but if not and you want to just try if that works, you can just download the package manually from NuGet (*.nupkg is a zip-file). Copying the file manually to the execution path could do.

@dmitry-a-morozov
Copy link
Member Author

That worked ! Thanks
Except MsBuild doesn't know to resolve ~ so I had to hard code path to my home. Which is not great.
Let me know if you can come up more generic solution that not tided to particular user.

You can close this issue in favor #498 .

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

3 participants