Search code examples
f#type-providers

Creating more than one root type with generative type provider


Generative type providers seem to have an issue with having more than one root type. Complete repro is available here: https://gist.github.com/dsevastianov/46d1a8495c4af46a9875. Following example

#r @"SampleProvider.dll"
type Birch = Sample.Sample<"birch">
type Elm = Sample.Sample<"elm">

let birch = Birch.birch()
let elm = Elm.elm()
elm.Branches <- ([|Elm.elm()|])

fails at compile time (not at design time):

FSC: error FS2014: A problem occurred writing the binary 'obj\Debug\Tests.dll': 
Error in pass3 for type Schema, error: Error in GetMethodRefAsMethodDefIdx for 
mref = (".ctor", "ZipLookup"), error: Exception of type Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter+MethodDefNotFound' was thrown.

Solution

  • Turns out that it is necessary to create separate temp assembly for each root type. I amended Gist to reflect the solution: https://gist.github.com/dsevastianov/46d1a8495c4af46a9875