[.net] An unhandled exception of type 'SerializationException'

Started by
3 comments, last by PumpkinPieman 18 years, 1 month ago
Alright, I've been trying to write an object data to a file for 3 hours ... I'm pretty much at my whits end. An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll Additional information: The type $ArrayType$0x7b463bb7 in Assembly LSpriteEdit, Version=1.0.2250.26616, Culture=neutral, PublicKeyToken=null is not marked as serializable.

#define SStringToString(s) (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(s)
#using <mscorlib.dll>
#using <system.dll>
#using <system.runtime.serialization.formatters.soap.dll>
#include <tchar.h>
#include <map>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Runtime::Serialization;
using namespace System::Runtime::Serialization::Formatters::Binary;


[Serializable]  __gc class LSF_SPRITEFILE : public System::Object
{
public:
	BYTE	filetype __nogc [3];
	BYTE	version;
	BYTE	filename __nogc [80];
};

[Serializable]  __gc class LSF_TEXTUREMASK : public System::Object
{
public:
	BYTE	name __nogc [30];
	float	x __nogc [2];
	float	y __nogc [2];

public:
	System::String __gc *ToString(void){

		return S"";
	}
};

[Serializable]  __gc class LSF_FRAMESET : public System::Object
{
public:
	BYTE animationSetName __nogc [30];
	DWORD numberFrames;

public:
	System::String __gc *ToString(void){

		return S"";
	}
};

[Serializable]  __gc class LSF_FRAMEINFO : public System::Object
{
public:
	DWORD frameNum;
	BYTE	maskName __nogc [30];
	float	position __nogc [2];
	float	scale __nogc [2];
	float	centre __nogc [2];
	float	rotation;
	DWORD	diffuse;
	DWORD duration;
	float	depth;

public:
	System::String __gc *ToString(void){

		return S"";
	}
};





bool SpriteModel::saveFile(System::String* filename)
{
	Stream* stream = File::Open(filename, FileMode::Create);
	BinaryFormatter* bf = new BinaryFormatter();
	LSF_TEXTUREMASK*tm = new LSF_TEXTUREMASK;

	tm->x[0] = 10;
	tm->x[1] = 5;
	tm->y[0] = 10;
	tm->y[1] = 5;

	bf->Serialize(stream, tm);

	return false;
}




No matter what I do it throws an exception // lessbread edit - go easy on the long titles! // PumpkinPieman edit - I would if I wasn't so ticked off ... [Edited by - PumpkinPieman on February 28, 2006 2:34:56 PM]
Advertisement
The .NET serializer doesn't know what to do with your unmanaged arrays in the LSF_TEXTUREMASK type. Either make them managed arrays or use another mechanism instead of serialization.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
I assumed that since they were static that I wouldn't have to delete them if the object was going to be deleted anyway. I'm new to .NET so I'm guessing I made the wrong assumption...
I don't see any static members?
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Bleh, I used the wrong word. At any rate, arrays can't be declared as __gc, only __nogc.

This topic is closed to new replies.

Advertisement