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

SqlEnumProvider breaks VS 2019 #410

Open
1 task done
bigby-the-wolf opened this issue Sep 17, 2021 · 2 comments
Open
1 task done

SqlEnumProvider breaks VS 2019 #410

bigby-the-wolf opened this issue Sep 17, 2021 · 2 comments
Assignees

Comments

@bigby-the-wolf
Copy link

bigby-the-wolf commented Sep 17, 2021

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

  • I am willing to test the bug fix before next release
@smoothdeveloper
Copy link
Collaborator

@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:

member internal this.CreateRootType( typeName, query, connectionStringOrName, provider, configFile, kind: SqlEnumKind) =
let tempAssembly = ProvidedAssembly()
let providedEnumType = ProvidedTypeDefinition(tempAssembly, nameSpace, typeName, baseType = Some typeof<obj>, hideObjectMethods = true, isErased = false)
let connStr, providerName =
match DesignTimeConnectionString.Parse(connectionStringOrName, config.ResolutionFolder, configFile) with
| Literal value -> value, provider
| NameInConfig(_, value, provider) -> value, provider
#if !USE_SYSTEM_DATA_COMMON_DBPROVIDERFACTORIES
// not supported on netstandard 20?
raise ("DbProviderFactories not available" |> NotImplementedException)
#else
let adoObjectsFactory = DbProviderFactories.GetFactory( providerName: string)
use conn = adoObjectsFactory.CreateConnection()
conn.ConnectionString <- connStr
conn.Open()

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.

@xperiandri
Copy link

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

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