FSharp.Data.SqlClient icon indicating copy to clipboard operation
FSharp.Data.SqlClient copied to clipboard

SqlEnumProvider breaks VS 2019

Open bigby-the-wolf opened this issue 4 years ago • 2 comments

Issue Summary

While testing out F# for WebApi development I picked "FSharp.Data.SqlClient" for SQL access. I've based this on the "Get programming with F#" book. The book has working examples that use this library, although they are in .NET 4.0.

On latest VS 2019 and with .NET 5, using SqlEnumProvider inside a project works but referencing that project breaks VS .

Anything coming from that project (namespace, module, etc.) is marked FS0039 (not defined). The solution builds and runs as expected but VS marks everything from that project as not defined.

To Reproduce

The full repository I use is found here. Relevant files are AccountRepository from WebApiTest.Repositories.SqlServer and CompositionRoot from WebApiTest.WebApi.

The solution and DB schema is based on the one from the book, can be found here. (.NET 4.0)

SqlProgrammabilityProvider and SqlCommandProvider work like a charm. And if I comment out the SqlEnumProvider line, VS sees everything from that project.

Steps to reproduce the behavior:

  • Create a project that uses SqlEnumProvider.
  • Reference that project inside another project in the same solution.

Error

Here is an image with the problem area:

image

What I've tried so far:

  • .NET 4.0 project (my own, not the book one, that one works for some reason)
  • moving code around in the WebApiTest.Repositories.SqlServer project into separate namespaces, modules, files
  • LocalDb, MS SQLServer container based on 2019-latest
  • Different solutions, calling from a Console project, ASP .NET WebApi project
  • Nuget and Paket (also tried force reddirect)
  • VS 2022 Preview latest (that opens another can of worms, nothing is working from this package because some problem with "System.Data.SqlClient" version 4.4.0.0)

I've opened a thread on StackOverflow here and someone else reproduced this.

I've also opened the resulting .dll file for the repository with dotPeek from JetBrains and the namespace/module/code is there.

And what I've observed is that SqlEnumProvider does not provide IntelliSense for the SQL query, only the command one does. SqlEnumProvider shows query errors only on project build. Is this normal?

Expected behavior

Referencing a project that uses SqlEnumProvider should work.

What you can do

  • [x] I am willing to test the bug fix before next release

bigby-the-wolf avatar Sep 17 '21 18:09 bigby-the-wolf

@MrGodlike6 thanks for the extensive bug report.

What I remember on top of my head is that SqlEnumProvider relies on some ADO.NET APIs that the two other type providers are not relying on:

https://github.com/fsprojects/FSharp.Data.SqlClient/blob/eb45a54728545429339b619acc69d2871a9bbd30/src/SqlClient.DesignTime/SqlEnumProvider.fs#L65-L82

It seems you are running under .net 5, but I'm not sure if it loads the provider which is compiled with USE_SYSTEM_DATA_COMMON_DBPROVIDERFACTORIES or not, which has impact on the code above.

Another thing is that SqlEnumProvider is the only one being a generative type provider (rather than erased one) and I'm not sure if it has impact on the usage of this library under .net 5 runtime.

I don't have time to investigate right now, but one thing to test would be if the code surounding db provider factories works properly outside the context of a type provider, and of course, running through the issue with debugger attached to the editor instanciating/running the provider.

Thanks again for the report and all the references.

smoothdeveloper avatar Sep 26 '21 16:09 smoothdeveloper

Looks like the provider must be compiled for the latest .NET in order to make this work As .NET 6 has it https://docs.microsoft.com/en-us/dotnet/api/system.data.common.dbproviderfactories?view=net-6.0

xperiandri avatar Aug 28 '22 21:08 xperiandri