Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copy a class to avoid the referenced object going away
Message
From
06/11/2010 13:14:02
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
Miscellaneous
Thread ID:
01488462
Message ID:
01488467
Views:
38
>>Hi All,
>>
>>I am trying to build a list of objects but if the underlying referenced object changes or goes away I have problems. To avoid this I am trying some code I found on c-shaprcorner to copy an object. I have tried two different versions, but both blow up on the third line and I am unable at the moment to find why. The objects passed in appear to be valid and the entity object has the [serializable] attribute on it.
>>
>>Option One
>>
>>public static LocationEntity MakeEntityCopy(LocationEntity entityToIsolate)
>>{
>>	MemoryStream stream = new MemoryStream();
>>	IFormatter formatter = new BinaryFormatter();
>>	formatter.Serialize(stream, entityToIsolate);
>>	stream.Seek(0, 0);
>>	LocationEntity IsolatedEntity = (LocationEntity)formatter.Deserialize(stream);
>>	stream.Close();
>>	return IsolatedEntity;
>>}
>>
>>
>>Option Two
>>
>>public static LocationEntity MakeEntityCopy(LocationEntity entityToIsolate)
>>{
>>	MemoryStream stream = new MemoryStream();
>>	BinaryFormatter bf = new BinaryFormatter();
>>	bf.Serialize(stream, entityToIsolate);
>>	stream.Position = 0;
>>	LocationEntity IsolatedEntity = (LocationEntity)bf.Deserialize(stream);
>>	stream.Close();
>>	return IsolatedEntity;
>>}
>>
>>
>>Is there anything obvious I am missing?
>
>What is LocationEntity ? Simply marking it as serializable doesn't neccessarily make it so .....
>And what's the exact exception ?


OK, stupid me. I wrapped the call in a try catch and this is the error
Type 'BTSystems.PantryWare.Business.ABusinessEntity' in Assembly 'BTSystems.PantryWare.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

What is needed for the class to be Serializable other than the attribute?
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform