Not able to pass an instance of a class over a network through OnSerializeNetworkView or an RPC

Is there a way to pass an instance of a class in the OnSerializeNetworkView function or a RPC. I need to pass a class over a network. But ONSerializeNetworkView and RPC’s both only allow booleans, chars, shorts, ints, floats, quaternions, Vector3’s, Networkplayers and NetworkID’s as parameters.

If this is not possible in any way, does someone know an alternative?

Thanks in advance…

The way to do this is using .net's binary serialization. It's not as straightforward as it sounds, and it took my several weeks to find this solution!

EDIT: I have put underscores _ in front of all the generics, as well as System.IO to stop UnityAnswers from interpreting them as html tags (grrrrrrrr)

using System;
using "System.IO"; // Get rid of the quotes, they're only there to fix auto-linking
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Reflection;

using UnityEngine;
using System.Collections;

// This class sends and recieves an object of type 'Info'. You can replace this
// with whatever you need to.

public class InfoSender : MonoBehaviour {

    public void SendInfo(Info info)
    {
        byte[] message = SerializeObject<_Info>(info); // should be just Info, not _Info
        networkView.RPC("RecieveInfo", RPCMode.Others, message);
        //Debug.Log(message);
    }

    [RPC] void RecieveInfo(byte[] dataStream)
    {
        MemoryStream stream = new MemoryStream(dataStream);
        stream.Position = 0;
        BinaryFormatter bf = new BinaryFormatter();
        bf.Binder = new VersionFixer();

        Info newInfo = (Info)bf.Deserialize(stream);

        // now you can use the recieved data however you need to!
    }

    byte[] SerializeObject<_T>(_T objectToSerialize)
                    //same as above, but should technically work anyway
    {
        BinaryFormatter bf = new BinaryFormatter();
        MemoryStream memStr = new MemoryStream();

        bf.Serialize(memStr, objectToSerialize);
        memStr.Position = 0;

        //return "";
       return memStr.ToArray();
    }
}

// This class fixes up problems with assembly mismatch between different
// kinds of build. For example, it allows you to use it between a standalone
// and the editor.

sealed class VersionFixer : SerializationBinder 
{
    public override Type BindToType(string assemblyName, string typeName) 
    {
        Type typeToDeserialize = null;

        // For each assemblyName/typeName that you want to deserialize to
        // a different type, set typeToDeserialize to the desired type.
        String assemVer1 = Assembly.GetExecutingAssembly().FullName;

        if (assemblyName != assemVer1) 
        {
            // To use a type from a different assembly version, 
            // change the version number.
            // To do this, uncomment the following line of code.
             assemblyName = assemVer1;

            // To use a different type from the same assembly, 
            // change the type name.
        }

        // The following line of code returns the type.
        typeToDeserialize = Type.GetType(String.Format("{0}, {1}", typeName, assemblyName));

        return typeToDeserialize;
    }

}

I'm assuming you have enough knowledge of RPC calls to adapt this to your needs.