I have different objects I would like to be able to load and save on a webserver. So I have made them as Class objects.
As example I have [Score] which I will be using for producing a hiscore on a server.
Score.cs
using System.Runtime.Serialization;
[System.Serializable]
public class Score
{
public long Total;
public string Name;
public Score(){}
public Score(string name, long total)
{
Total = total;
Name = name;
}
}
This code I want to use as data structure (n-tier architecture) in both Unity3D as clientside structure and in my ASP.NET server I use it as serverside object too.
What I do is that I want to build a list-array like this:
List<Score> hiscores = new List<Score>();
hiscores.add (new Score("Player 1", 10000));
hiscores.add (new Score("Player 2", 20000));
hiscores.add (new Score("Player 3", 30000));
hiscores.add (new Score("Player 4", 40000));
… then I want to serialize it into a bytearray so I can use WWWform to POST it:
MemoryStream membytes = new MemoryStream();
BinaryFormatter binFormatter = new BinaryFormatter();
binFormatter.Serialize(membytes, hiscores );
…
then I call my WWWform and it goes to the webserver as expected.
BUT - on the webserver, in ASP.NET | Open-source web framework for .NET I get an error 500 telling me that it cannot load the assemble for deserializing the data???
HUH?! I’ve read someone suggesting to make the assemble outside Unity3D and then link it externally, but as Unity3D uses MONO and ASP.NET uses .NET… is that possible in my situation or am I on the wrong path somehow?
I can easily transfer a simle bytearray with values from 0x00 to 0xff to my ASP.NET and save it. But once I start using serialize/deserialize things messes up?