Getting a compilation error by the type provided

I am working on a TypeProvider that reads an XSD file and provides a type for each type defined in XSD. However, I have a problem in the code below

type schema = XmlProviders.Schema<"file.xsd"> type Bazzer = { Sum : XmlProviders.bar } 

in the last line, I get a compilation error saying that XmlProviders.bar does not exist. The implementation of how I define types is 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 the XmlProviders.bar type is being created, because if I add an extra line to define Type provider.AddMember t , then I get an error

A provider of type "XmlProviders.SampleTypeProvider" reported an error: the container type for "XmlProviders.bar" was already set to "XmlProviders.Schema"

Where XmlProviders.Schema is the ProvidedTypeDefinition identified by provider

I lost a little because the compiler complains that this type is not there, if I explicitly add it, I get an error message that it is already there

+5
source share
1 answer

An answer is found, so those ending in the same situation

line

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

where a certain type of nested type should be without assembly and namespace

 let t = ProvidedTypeDefinition(name,baseType = Some typeof<obj>) 
+4
source

Source: https://habr.com/ru/post/958230/


All Articles