Serialize/deserialize on ASP.NET (c#) server - possible?

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?

That’s no problem managed code is managed code :wink: C# (and of course UnityScript and boo) is compiled to the common intermediate language. If you create a C# dll in visual studio you can use it in Unity like a script file :wink:

I never used ASP (neither with .NET or without ;)) so i can’t say if there are problems to use a “normal” managed dll but i’m quite sure it will work just fine …

You can visit to this link to get help regarding your queries
http://techgurulab.com/

if you want to increase your programming skills and also play to quiz then most welcome to this website: http://techgurulab.com/

sounds like you need to use a dll containing the definition of the serializable class/classes.
for serialization to work the code that calls the method needs access to the definition aka the object graph.

if you target .Net v2.0 then mono will have no issues since that is what it is built off, or just target mono since its on your system. Note this only applies to your dll.

So package a dll with the class definition and import it from asp page and unity.