5

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

Rune FS
  • 21,497
  • 7
  • 62
  • 96
  • It looks like you are aware of the GitHub workitem already, but I'll add it here so as to make other people aware your efforts [Support XSD in XmlProvider](https://github.com/fsharp/FSharp.Data/issues/57) and just in case I cross link my related question (feel free to remove this if I'm too intruding) [How to approach writing an F# type provider that enforces complex schema?](http://stackoverflow.com/questions/20024418/how-to-approach-writing-an-f-type-provider-that-enforces-complex-schema). Let's see if I'm of help here (that is, I'm rather rookie with this). – Veksi Dec 10 '13 at 08:50

1 Answers1

4

Found the answer, so to those that end in the same situation

the line

let t = ProvidedTypeDefinition(thisAssembly,
                                   ns,
                                   name,
                                   baseType = Some typeof<obj>)

where the nested type is defined should be without assembly and namespace

let t = ProvidedTypeDefinition(name,baseType = Some typeof<obj>)
Rune FS
  • 21,497
  • 7
  • 62
  • 96