This is really @WaldemarGałęzinowski's answer https://mcmap.net/q/297333/-unable-to-generate-a-temporary-class-result-1-error-cs0030-cannot-convert-type-39-type-39-to-39-type-39
expanded a bit.
xsd.exe
has an optimization that kicks in when you have a single unbounded element without attribute in a sequence.
The optimization will avoid creating a special type for the parent and instead make it an array of children.
ChildType[] Parent { get; set; }
instead of ParentType Parent { get; set; }
and you access the children like Parent[0]
instead of Parent.Child[0]
.
(I find this optimization a bit confusing sometimes)
What is happening here is you have one more level of unbounded, attribute-less element
The optimization is applied twice and the result is GrandChildType[][] Parent {get; set;}
and you access your favorite first grandchild like Parent[0][0]
instead of Parent.Child[0].GrandChild[0]
.
The problem is the .Net serializer does not support arrays of arrays and generates invalid code.
I have no idea why Microsoft has not fixed this bug in all these years but the workaround is simple.
Just force xsd.exe
to generate a class for the parent or child by adding an optional attribute or an optional element to the sequence. e.g.
Which leads to Parent[0].GrandChild[0]