InvalidOperationException when serializing clasess generated by xsd.exe

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
HI,
I have a source XML file then with xsd.exe I generate the *.xsd then the *.cs file where i have these classes
<pre class="prettyprint //------------------------------------------------------------------------------
// <auto-generated>
// Este código fue generado por una herramienta.
// Versión del motor en tiempo de ejecución:2.0.50727.5456
//
// Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si
// se vuelve a generar el código.
// </auto-generated>
//------------------------------------------------------------------------------

using System.Xml.Serialization;

//
// This source code was auto-generated by xsd, Version=2.0.50727.3038.
//


/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.sat.gob.mx/cfd/3", IsNullable=false)]
public partial class Comprobante {

private ComprobanteEmisor[] emisorField;

private ComprobanteReceptor[] receptorField;

private ComprobanteConceptosConcepto[][] conceptosField;

private ComprobanteImpuestos[] impuestosField;

private string versionField;

private string serieField;

private string folioField;

private string fechaField;

private string selloField;

private string formaDePagoField;

private string noCertificadoField;

private string certificadoField;

private string condicionesDePagoField;

private string subTotalField;

private string monedaField;

private string totalField;

private string tipoDeComprobanteField;

private string metodoDePagoField;

private string lugarExpedicionField;

/// <comentarios/>
[System.Xml.Serialization.XmlElementAttribute("Emisor")]
public ComprobanteEmisor[] Emisor {
get {
return this.emisorField;
}
set {
this.emisorField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlElementAttribute("Receptor")]
public ComprobanteReceptor[] Receptor {
get {
return this.receptorField;
}
set {
this.receptorField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlArrayItemAttribute("Concepto", typeof(ComprobanteConceptosConcepto), IsNullable=false)]
public ComprobanteConceptosConcepto[][] Conceptos {
get {
return this.conceptosField;
}
set {
this.conceptosField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlElementAttribute("Impuestos")]
public ComprobanteImpuestos[] Impuestos {
get {
return this.impuestosField;
}
set {
this.impuestosField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string version {
get {
return this.versionField;
}
set {
this.versionField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string serie {
get {
return this.serieField;
}
set {
this.serieField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string folio {
get {
return this.folioField;
}
set {
this.folioField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string fecha {
get {
return this.fechaField;
}
set {
this.fechaField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string sello {
get {
return this.selloField;
}
set {
this.selloField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string formaDePago {
get {
return this.formaDePagoField;
}
set {
this.formaDePagoField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string noCertificado {
get {
return this.noCertificadoField;
}
set {
this.noCertificadoField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string certificado {
get {
return this.certificadoField;
}
set {
this.certificadoField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string condicionesDePago {
get {
return this.condicionesDePagoField;
}
set {
this.condicionesDePagoField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string subTotal {
get {
return this.subTotalField;
}
set {
this.subTotalField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Moneda {
get {
return this.monedaField;
}
set {
this.monedaField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string total {
get {
return this.totalField;
}
set {
this.totalField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string tipoDeComprobante {
get {
return this.tipoDeComprobanteField;
}
set {
this.tipoDeComprobanteField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string metodoDePago {
get {
return this.metodoDePagoField;
}
set {
this.metodoDePagoField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string LugarExpedicion {
get {
return this.lugarExpedicionField;
}
set {
this.lugarExpedicionField = value;
}
}
}

/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
public partial class ComprobanteEmisor {

private ComprobanteEmisorDomicilioFiscal[] domicilioFiscalField;

private ComprobanteEmisorExpedidoEn[] expedidoEnField;

private ComprobanteEmisorRegimenFiscal[] regimenFiscalField;

private string rfcField;

private string nombreField;

/// <comentarios/>
[System.Xml.Serialization.XmlElementAttribute("DomicilioFiscal")]
public ComprobanteEmisorDomicilioFiscal[] DomicilioFiscal {
get {
return this.domicilioFiscalField;
}
set {
this.domicilioFiscalField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlElementAttribute("ExpedidoEn")]
public ComprobanteEmisorExpedidoEn[] ExpedidoEn {
get {
return this.expedidoEnField;
}
set {
this.expedidoEnField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlElementAttribute("RegimenFiscal")]
public ComprobanteEmisorRegimenFiscal[] RegimenFiscal {
get {
return this.regimenFiscalField;
}
set {
this.regimenFiscalField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string rfc {
get {
return this.rfcField;
}
set {
this.rfcField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string nombre {
get {
return this.nombreField;
}
set {
this.nombreField = value;
}
}
}

/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
public partial class ComprobanteEmisorDomicilioFiscal {

private string calleField;

private string coloniaField;

private string localidadField;

private string municipioField;

private string estadoField;

private string paisField;

private string codigoPostalField;

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string calle {
get {
return this.calleField;
}
set {
this.calleField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string colonia {
get {
return this.coloniaField;
}
set {
this.coloniaField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string localidad {
get {
return this.localidadField;
}
set {
this.localidadField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string municipio {
get {
return this.municipioField;
}
set {
this.municipioField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string estado {
get {
return this.estadoField;
}
set {
this.estadoField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string pais {
get {
return this.paisField;
}
set {
this.paisField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string codigoPostal {
get {
return this.codigoPostalField;
}
set {
this.codigoPostalField = value;
}
}
}

/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
public partial class ComprobanteEmisorExpedidoEn {

private string calleField;

private string coloniaField;

private string localidadField;

private string municipioField;

private string estadoField;

private string paisField;

private string codigoPostalField;

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string calle {
get {
return this.calleField;
}
set {
this.calleField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string colonia {
get {
return this.coloniaField;
}
set {
this.coloniaField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string localidad {
get {
return this.localidadField;
}
set {
this.localidadField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string municipio {
get {
return this.municipioField;
}
set {
this.municipioField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string estado {
get {
return this.estadoField;
}
set {
this.estadoField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string pais {
get {
return this.paisField;
}
set {
this.paisField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string codigoPostal {
get {
return this.codigoPostalField;
}
set {
this.codigoPostalField = value;
}
}
}

/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
public partial class ComprobanteEmisorRegimenFiscal {

private string regimenField;

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Regimen {
get {
return this.regimenField;
}
set {
this.regimenField = value;
}
}
}

/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
public partial class ComprobanteReceptor {

private ComprobanteReceptorDomicilio[] domicilioField;

private string rfcField;

private string nombreField;

/// <comentarios/>
[System.Xml.Serialization.XmlElementAttribute("Domicilio")]
public ComprobanteReceptorDomicilio[] Domicilio {
get {
return this.domicilioField;
}
set {
this.domicilioField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string rfc {
get {
return this.rfcField;
}
set {
this.rfcField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string nombre {
get {
return this.nombreField;
}
set {
this.nombreField = value;
}
}
}

/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
public partial class ComprobanteReceptorDomicilio {

private string calleField;

private string noExteriorField;

private string noInteriorField;

private string coloniaField;

private string localidadField;

private string municipioField;

private string estadoField;

private string paisField;

private string codigoPostalField;

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string calle {
get {
return this.calleField;
}
set {
this.calleField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string noExterior {
get {
return this.noExteriorField;
}
set {
this.noExteriorField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string noInterior {
get {
return this.noInteriorField;
}
set {
this.noInteriorField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string colonia {
get {
return this.coloniaField;
}
set {
this.coloniaField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string localidad {
get {
return this.localidadField;
}
set {
this.localidadField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string municipio {
get {
return this.municipioField;
}
set {
this.municipioField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string estado {
get {
return this.estadoField;
}
set {
this.estadoField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string pais {
get {
return this.paisField;
}
set {
this.paisField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string codigoPostal {
get {
return this.codigoPostalField;
}
set {
this.codigoPostalField = value;
}
}
}

/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
public partial class ComprobanteConceptosConcepto {

private string cantidadField;

private string unidadField;

private string descripcionField;

private string valorUnitarioField;

private string importeField;

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string cantidad {
get {
return this.cantidadField;
}
set {
this.cantidadField = value;
}
}

/// <comentarios/>

[System.Xml.Serialization.XmlAttributeAttribute()]
public string unidad {
get {
return this.unidadField;
}
set {
this.unidadField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string descripcion {
get {
return this.descripcionField;
}
set {
this.descripcionField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string valorUnitario {
get {
return this.valorUnitarioField;
}
set {
this.valorUnitarioField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string importe {
get {
return this.importeField;
}
set {
this.importeField = value;
}
}
}

/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
public partial class ComprobanteImpuestos {

private ComprobanteImpuestosTrasladosTraslado[][] trasladosField;

private string totalImpuestosTrasladadosField;

/// <comentarios/>
[System.Xml.Serialization.XmlArrayItemAttribute("Traslado", typeof(ComprobanteImpuestosTrasladosTraslado), IsNullable=false)]
public ComprobanteImpuestosTrasladosTraslado[][] Traslados {
get {
return this.trasladosField;
}
set {
this.trasladosField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string totalImpuestosTrasladados {
get {
return this.totalImpuestosTrasladadosField;
}
set {
this.totalImpuestosTrasladadosField = value;
}
}
}

/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
public partial class ComprobanteImpuestosTrasladosTraslado {

private string impuestoField;

private string tasaField;

private string importeField;

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string impuesto {
get {
return this.impuestoField;
}
set {
this.impuestoField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string tasa {
get {
return this.tasaField;
}
set {
this.tasaField = value;
}
}

/// <comentarios/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string importe {
get {
return this.importeField;
}
set {
this.importeField = value;
}
}
}

/// <comentarios/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sat.gob.mx/cfd/3")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.sat.gob.mx/cfd/3", IsNullable=false)]
public partial class NewDataSet {

private Comprobante[] itemsField;

/// <comentarios/>
[System.Xml.Serialization.XmlElementAttribute("Comprobante")]
public Comprobante[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
}
[/code]
I fill an instance of my class <span style="color:#2b91af; font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Comprobante
then I try to serialize tha instance as follow:
<pre class="prettyprint XmlSerializer ser = new XmlSerializer(facturaXML.GetType());
TextWriter writer = new StreamWriter("pruebaXMLSalida.xml");
ser.Serialize(writer, facturaXML);
writer.Close();[/code]
when the fist line of the code above is executed I get this error:
No se puede generar una clase temporal (result=1).<br/>
error CS0030: No se puede convertir el tipo ComprobanteConceptosConcepto[] en ComprobanteConceptosConcepto<br/>
error CS0030: No se puede convertir el tipo ComprobanteImpuestosTrasladosTraslado[] en ComprobanteImpuestosTrasladosTraslado<br/>
error CS0029: No se puede convertir implícitamente el tipo ComprobanteConceptosConcepto en ComprobanteConceptosConcepto[]<br/>
error CS0029: No se puede convertir implícitamente el tipo ComprobanteImpuestosTrasladosTraslado en ComprobanteImpuestosTrasladosTraslado[]
The stack has the following message:
en System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)<br/>
en System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)<br/>
en System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)<br/>
en System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)<br/>
en System.Xml.Serialization.XmlSerializer..ctor(Type type)<br/>
en ConsoleApplication1.Program.GeneraArchivoXMLFactura(Comprobante facturaXML) en C:APHLDCOMFactura electrónicaCodigo FuenteConsoleApplication1ConsoleApplication1Program.cs:línea 30<br/>
en ConsoleApplication1.Program.Main(String[] args) en C:APHLDCOMFactura electrónicaCodigo FuenteConsoleApplication1ConsoleApplication1Program.cs:línea 18<br/>
en System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)<br/>
en System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br/>
en Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br/>
en System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br/>
en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)<br/>
en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br/>
en System.Threading.ThreadHelper.ThreadStart()
The context of my app is:
- Console App
- Windows 7 Ultimate
- Visual Studio 2012
- .NET Framework 4.0

I already read this link:
http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/6c132aac-ca68-4674-ad3d-1604c9ab2f4e http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/6c132aac-ca68-4674-ad3d-1604c9ab2f4e http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/6c132aac-ca68-4674-ad3d-1604c9ab2f4e
But I do have accessors to my private properties so Im not sure what else I am missing :S
any ideas please, svp, porfavor :D




View the full article
 
Back
Top