fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

Compile time error using generative provider with optional parameter from a netcore app #272

Closed samhanes closed 5 years ago

samhanes commented 5 years ago

Description

While working on this PR for SqlClient, I'm seeing an issue with generated types that contain an optional provided parameter. (i.e., where optionalValue is Some) at compile-time:

FSC : error FS2024: Static linking may not be used on an assembly referencing mscorlib (e.g. a .NET Framework assembly) when
generating an assembly that references System.Runtime (e.g. a .NET Core or Portable assembly). [C:\code\FSharp.Data.SqlClient\src\SqlClient.Tests\SqlClient.Tests.NetCoreApp\SqlClient.Tests.NetCoreApp.fsproj]

The TP appears to be working correctly at design time.

Note that the components are targeting:

Repro steps

Build the TP in this branch and try to compile SqlClient.Tests.NetCoreApp. The provider is called TestGenerativeProvider.

Or, create a generative TP that produces a type with a method that contains an optional parameter, with a net461 DTC and a netstandard2.0 RTC. Reference a generated type from a netcore application and attempt to compile.

Expected behavior

Consuming application should compile and types should work as expected at runtime.

Actual behavior

Compile-time error as described above.

Known workarounds

Switching to erased types also solves this issue.

dsyme commented 5 years ago

@samhanes Hmmm.... it feels like there must be something wrong with the TP if an mscorlib type is being generated when targeting NetCoreApp. I'll take a look

dsyme commented 5 years ago

THe bug in TPSDK is here:

                                    let ctor = typeof<System.Runtime.InteropServices.OptionalAttribute>.GetConstructor([||])
                                    let ca = mkILCustomAttribMethRef (transCtorSpec ctor, [], [], [])
                                    pb.SetCustomAttribute ca

The type OptionalAttribute is not being remapped to the target platform. WIll fix

dsyme commented 5 years ago

@samhanes fixed in master

samhanes commented 5 years ago

Terrific, thanks!