I'm having some trouble with binary serialization in C#... I should add that I'm a relative noob with C#, so please explain in simple terms :)
Anyway, I have this class (truncated for clarity):
[Serializable]
public class Player : Ship {
And Ship looks like this (again, truncated):
[Serializable]
public class Ship : TiledActor {
public float MaxUserTurnPerSecond;
public float RemainingShieldStrength;
public float MaxShieldStrength;
public float ShieldRechargeRate;
public float ShieldRechargeDelay;
public Color ShieldColor;
public float ThrusterAccelerationScale;
public Color RippleTrailColor;
public float MinimumRippleSpeed;
public float MaxEnergy;
public float CurrentEnergy;
public float EnergyRechargeRate;
public float MaxSecondaryAmmoCapacity;
public int CurrentSecondaryAmmoCount;
public Weapon PrimaryWeapon;
public Weapon SecondaryWeapon;
protected ShieldActor ShieldTex;
[NonSerialized]
public MoXNA.ParticleMachines.PM_Explosion_Particle_Count ExplosionSize;
[NonSerialized]
protected MoXNA.ParticleMachines.MinSpeedRippleTrail rippleTrail;
/* ... Truncated here */
So, as you can see, I wish to serialize the Player class. However, when I try this, I get this error:
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
Additional information: Type 'MoXNA.ParticleMachines.MinSpeedRippleTrail' in Assembly 'SpaceshipInABox, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
The odd thing here is that I marked rippleTrail (which is the MinSpeedRippleTrail object) as [NonSerialized]... I don't want to serialize it (it's just a visual effect).
I used "Find all references" and that's the only MinSpeedRippleTrail object in the entire program, so what the hell?
Thanks.
Serializableto theMinSpeedRippleTrailclass/struct anyhow, perhaps even though theNonSerializedattribute is applied, it still checks first whether it can be serialized?