J'essaie de sérialiser un résultat LINQ de cette façon:Erreur résultat sérialisation LINQ
Private Sub btnXML_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnXML.Click
Try
Dim sourceForXML = From detail In PayrollRegisterModel.CompanyDetails
Join shifts In PayrollRegisterModel.Shifts On detail.Id_companydetail Equals shifts.Id_companydetail
Dim xmlFile As New Xml.Serialization.XmlSerializer(sourceForXML.GetType)
Dim xw As System.Xml.XmlWriter = Xml.XmlWriter.Create("C:/Abcom/XMLRegister.xml")
xmlFile.Serialize(xw, sourceForXML)
Catch ex As Exception
MsgBox(e.ToString)
End Try
End Sub
mais dans la ligne:
Dim xmlFile As New Xml.Serialization.XmlSerializer(sourceForXML.GetType)
Je reçois cette erreur:
**System.InvalidOperationException was caught
Message=To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. System.Data.Objects.ObjectQuery`1[[VB$AnonymousType_0`2[[Abcom.Payroll.Register.CompanyDetail, Abcom.Payroll.Register, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Abcom.Payroll.Register.Shift, Abcom.Payroll.Register, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Abcom.Payroll.Register, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] does not implement Add(System.Object).
Source=System.Xml
StackTrace:
at System.Xml.Serialization.TypeScope.GetEnumeratorElementType(Type type, TypeFlags& flags)
at System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference)
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
at System.Xml.Serialization.ModelScope.GetTypeModel(Type type, Boolean directReference)
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at Abcom.Payroll.Register.MainWindow.btnXML_Click(Object sender, RoutedEventArgs e) in C:\Abcom\Inhouse Development Tools\Abcom.Payroll.Register\Abcom.Payroll.Register\MainWindow.xaml.vb:line 415**
Est-ce que quelqu'un sait ce qui se passe ici et comment puis-je résoudre ce problème?
Cordialement,
Claudio
actualy Je ne sais pas exactement comment traduire ce code de C# à VB. De toute façon, ma solution sera de changer ma langue! Merci beaucoup! – Claudio
@Claudio Oups^_^ne voulait pas vous faire choisir une autre langue) Bonne chance en C#, c'est puissant et incroyable, à mon humble avis. Vous le souhaitez (tôt ou tard))) –