Closed Tarmil closed 5 years ago
Looks like maybe you want to do (note both let asm
bindings)
[<TypeProvider>]
type MyProvider (cfg: TypeProviderConfig) as this =
inherit TypeProviderForNamespaces(cfg)
let asm = Assembly.GetExecutingAssembly()
let rootNamespace = "TpBug"
do
let templateTy = ProvidedTypeDefinition(asm, rootNamespace, "TpBugProvider", None, isErased = false)
templateTy.DefineStaticParameters([ProvidedStaticParameter("param", typeof<string>)], fun typename pars ->
let asm = ProvidedAssembly()
let n = pars.[0] :?> string
let ty = ProvidedTypeDefinition(asm, rootNamespace, typename, Some typeof<obj>, isErased = false)
ProvidedConstructor([], fun _ -> <@@ () @@>) |> ty.AddMember
asm.AddTypes([ty])
ty
)
this.AddNamespace(rootNamespace, [templateTy])
[<assembly:TypeProviderAssembly>]
do ()
Thank you for sample @kevmal
@Tarmil if you take a look at TP template, created by Don, it also create ProvidedAssembly
inside t.DefineStaticParameters
(for each call/usage of TP)
https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/templates/content/basic/src/MyProvider.DesignTime/MyProvider.DesignTime.fs#L75
Thanks guys! That was indeed the problem.
Description
Compilation fails when trying to instantiate the same generative provider with different static parameters, when this provider has a constructor on the root generated type.
Repro steps
Clone https://github.com/Tarmil/GenerativeTPCtorBug
dotnet build
Expected behavior
The project compiles.
Actual behavior
The project fails with:
The error disappears when commenting out one of the ctor calls in
User/Library.fs
.Known workarounds
None.
Related information