I'm working on a TypeProvider that reads an XSD file and provides a type for each type defined in the XSD. However I have a problem in the below code
type schema = XmlProviders.Schema<"file.xsd">
type Bazzer = {
Sum : XmlProviders.bar
}
on the last line I get a compilation error saying that XmlProviders.bar does not exist. The implementation of how I define the types are as follows
let defineType (xType : XElement) =
let name = xType.Attribute(XName.Get "name").Value
let t = ProvidedTypeDefinition(thisAssembly,
ns,
name,
baseType = Some typeof<obj>)
let ctor = ProvidedConstructor(parameters = [ ],
InvokeCode= (fun args -> <@@ "" :> obj @@>))
t.AddMember ctor
do provider.DefineStaticParameters(parameters, fun tyName args ->
let filename = args.[0] :?> string
let main = ProvidedTypeDefinition(thisAssembly,ns,
tyName,
baseType = Some typeof<obj>)
//Elements is a list of XElement
elements |> List.map defineType |> ignore
main
I know that a XmlProviders.bar type is created because if I add an additional line to defineType provider.AddMember t
then I get an error saying
The type provider 'XmlProviders.SampleTypeProvider' reported an error: container type for 'XmlProviders.bar' was already set to 'XmlProviders.Schema'
Where XmlProviders.Schema
is the ProvidedTypeDefinition
identified by provider
I'm a bit lost on why the compiler complains that the type is not there while if I explicitly add it I get the error that it's already there
Found the answer, so to those that end in the same situation
the line
where the nested type is defined should be without assembly and namespace