Serialization issue

Serialization issue

Old forum URL: forums.lhotka.net/forums/t/5230.aspx


Golfnut1969 posted on Tuesday, August 12, 2008

I'm a huge fan of the CSLA framework but unfortunately am working on an existing system that doesn't use anything close to this.  I have however tried implementing some of the technologies that Rockford as presented. 

I'm having an issue where I'm trying to serialize a Business Object that has a property that is a file (could be any kind of file {.txt, .doc, .pdf, etc}).  I load the file as a Byte array and the property itself is of type byte().  The only other property of this file is the file name. So I've got two properties, one of a String type and the other byte(). 

My problem is that the object won't serialize, or I should say it will serialize, but when I use the Binaryformatter.Deserialize it returns nothing?

Any thoughts, comments, suggestions will be most welcome.

Thanks for taking the time to read this.

ajj3085 replied on Tuesday, August 12, 2008

Did you mark your class with the Serializable attribute?

Golfnut1969 replied on Tuesday, August 12, 2008

Yes, it's got the serialization attribute. 

Golfnut1969 replied on Tuesday, August 12, 2008

I found the issue.  I assumed the problem was the Byte Array property type, but it was something much simpler.  Thanks for your time.

ajj3085 replied on Tuesday, August 12, 2008

What was the problem?

richardb replied on Tuesday, August 12, 2008

Not sure if you can serialize the file like that.  What are you trying to do with the bytes at the other end?  I'm guessing it doesn't know how to deserialize it back to a file.

richardb replied on Tuesday, August 12, 2008

OK you fixed it.

Golfnut1969 replied on Tuesday, August 12, 2008

The file is kept as a byte array simply because this enables me to include a file in my object regardless of the type of file.  I can then send it with the object anywhere I want and then restore it to a hard disk anywhere and simply name the new file with the correct extension and any name I want.

 

Copyright (c) Marimer LLC