System.IO.InvalidDataException

Options
L1nk27
edited April 2014 in DotNet
When i send a Register Request to my Server it gave me the following Error:
[code2=csharp]System.IO.InvalidDataException: cannot serialize(): System.Guid[/code2]

I had found that the Problem is in the following lines:
[code2=csharp]XmlSerializer mySerializer = new XmlSerializer(typeof(RegisterSubServerData));
StringReader inStream = new StringReader(registerRequest.RegisterSubServerOperation);
var registerData = (RegisterSubServerData) mySerializer.Deserialize(inStream);[/code2]

My RegisterSubServerData.cs:
[code2=csharp]public class RegisterSubServerData
{
public string GameServerAddress { get; set; }
public Guid? ServerId { get; set; }
public int? TcpPort { get; set; }
public int? UdpPort { get; set; }
public int ServerType { get; set; }
public string ApplicationName { get; set; }
}[/code2]

I don't know how i can fix this.
I hope you can help me.

Sorry for my bad English i am German :D

Comments

  • Tobias
    Options
    Being German doesn't mean your English must be bad ;)

    Where did you get the XmlSerializer? I don't recall it's a class in Photon.
    Guid as type is not supported by Photon. We usually send them as string or byte[]. If you want to send Guids, you will have to register the type as custom type.
    This hopefully helps:
    http://doc.exitgames.com/en/realtime/cu ... -in-photon
  • L1nk27
    Options
    So i should change the type of ServerId to string and change the set method from
    [code2=csharp]ServerId = Guid.NewGuid();[/code2]
    to
    [code2=csharp]ServerId = Guid.NewGuid().ToString();[/code2]
    ?

    And i use the XmlSerializer from System.Xml.Serialization
  • L1nk27 wrote:
    So i should change the type of ServerId to string and change the set method from
    [code2=csharp]ServerId = Guid.NewGuid();[/code2]
    to
    [code2=csharp]ServerId = Guid.NewGuid().ToString();[/code2]
    ?

    Yes, that is correct.

    Furthermore, you don't need to serialize the data yourself. Change your RegisterSubServerData class so that inherits from Photon.SocketServer.Rpc.Operation, and then you can do something like this in your outgoing peer:

    [code2=csharp]var data = new RegisterSubServerData();
    // initialize data here
    var request = new OperationRequest((byte)OperationCode.RegisterSubServer, data);
    this.SendOperationRequest(request, new SendParameters());[/code2]

    Take a look at the Loadbalancing.ServerToServer namespace for an example.