If the BindableObject does not serialize to xml properly you could always try changing the base class for TrackerName . Maybe ObservableObject from MVVM Helpers will work for you.
The other option is try and serialize as json instead of xml
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am attempting to create an XmlSerializer, and receive the following Exception:
System.InvalidOperationException: 'There was an error reflecting type 'PointTracker_Forms.TrackerName[]'.'
The line used to create the XmlSerializer is the following:
Dim xml As New XmlSerializer(GetType(T), New XmlRootAttribute(xmlroot))
And the TrackerName class is defined as follows:
using System.Diagnostics;
using System.Xml.Serialization;
using Xamarin.Forms;
namespace PointTracker_Forms
{
[XmlRoot("TrackerName"), XmlType("TrackerName"), DebuggerDisplay(@"TrackerName Name: {this.Name} Id: {this.Id}")]
public class TrackerName : BindableObject
{
public static readonly BindableProperty NameProperty = BindableProperty.Create("Name", typeof(string), typeof(TrackerName), "");
public static readonly BindableProperty IdProperty = BindableProperty.Create("Id", typeof(int), typeof(TrackerName), 0);
[XmlAttribute()] public string Name
{
get { return (string)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
[XmlAttribute()] public int Id
{
get { return (int)GetValue(IdProperty); }
set { SetValue(IdProperty, value); }
}
public TrackerName() : this("", 0) { }
public TrackerName(string name, int id) { this.Name = name; this.Id = id; }
public override string ToString() { return $"TrackerName Name = \"{this.Name}\" Id = {this.Id}"; }
}
}
You will notice that the TrackerName class DOES have a default/parameterless constructor. The 2 properties (Name & Id) are just a string & int (they are not any fancy types). You may also notice that there are 2 BindableProperty(s). I tried adding the XmlIgnore() attribute to these, but it did not help (I actually tried removing them completely & using regularly properties, but that didn't make any difference either). Everything I could find just tells me to make sure I have a default/parameterless constructor, but like I said, I do. What is the problem? Thanks.
If the BindableObject does not serialize to xml properly you could always try changing the base class for TrackerName . Maybe ObservableObject from MVVM Helpers will work for you.
The other option is try and serialize as json instead of xml