[Solved] WebGL & XmlSerialization combo doesn't work

Unity 5.3.2

I can communicate to my server just fine if I run it in the Game View.
But when I try to build to WebGL (Development build) and run, I get the error:

LoginRegisterData cannot be serialized because it does not have a default public constructor

But I do??

    public class LoginRegisterData
    {
  [XmlElement]
  public string Username { get; set; }
  [XmlElement]
  public string Password { get; set; }
  [XmlElement]
  public int Id { get; set; }
  [XmlElement]
  public string Pool { get; set; }
  [XmlElement]
  public bool Verified { get; set; }
  [XmlElement]
  public string FailMessage { get; set; }
  public LoginRegisterData() { }
    }

I really don’t know what to do at this point.

There is a PreserveAttribute in UnityEngine now. So add that to your constructor:

[Preserve]
public LoginRegisterData() {

}

My guess is that the constructor is being stripped. This should take care of it.

1 Like

I can’t put the PreserveAttribute on a constructor.

Oh sorry, put it on the class.

[Preserve]
public class LoginRegisterData
1 Like

Yes, that did it! Thank you!

You’re very welcome. :slight_smile: