Strange problem when deserializing

C

Chukkalove

I'm sorry this message is so long.
I have had to make some changes to an application written by a previous
developer who used unmanaged serialization to store complex objects to file.
The application is a RAD form designer to design screens for an embedded
system and he only allowed for a single type of target system.
My company now needs a designer for a 2nd type of system but because of the
unmanaged serialization, any changes to the application to allow for more
than a single set of form controls causes old project files to fail to load.
It's imperative that old projects can be opened.

The only solution I can come up with, because (due to time) it's impossible
to debug or write a file converter, (and I only want to maintain a single
set of source) is to compile an application for each target using
conditional defines.

There is only one control that differs from those found in the original
system.
This control is a simple label that can represent/display 1 of a possible 50
variables that are updated in real time. The list of variables is held as an
enumeration within the class and, in the designer, is selected from an list
in the property editor eg "ERT" or "NUM". To go with the enumeration are
matching arrays of string descriptions and display formats eg "###.#"

The simplest solution I could think of was creating the enumeration (plus
lists), for the 2nd control, and using conditional defines to select which
enumeration was used during compilation. I then compile the application
twice, once for target 1 and the other for target 2.
When testing.
Serializing target app 1. Old files read successfully. New files written
successfully. New files read successfully.
Serializing target app 2. (no old files to test). New files written
successfully. New files read unsuccessfully and fail with error message

"A first chance exception of type 'System.InvalidCastException' occurred in
skinlibrary.dll
Additional information: Specified cast is not valid."

Running target app 2. If I try to open one of the Old files (created by
target 1 app prior to changes), this opens with no error. It also opens
target 1 apps new files (post change) successfully.

As I say, all Ive done is added an alternative enumeration and 2 string
arrays.

Im not sure if Ive done something wrong, or if the application is getting
confused between dlls or there's something else.
For the original application, I use Debug/Release configs. For the 2nd
application I created DebugStr/ReleaseStr configs which contain the STR
conditional define. These have their own subdirectories off the \bin
directory.

Can anyone help please to find the source of the problem. Thanks
 
N

Nicholas Paldino [.NET/C# MVP]

Perhaps I am looking at this too simplisticly, but when saving your
project types for the new type of system, why not just have a flag in the
file that indicates what kind of serialization you are using? If no flag
exists, it is assumed it is the old version.

You can then look for this flag, and then branch your processing off
accordingly.

The conditional complilation solution seems VERY excessive to me.

Hope this helps.
 
C

Chukkalove

I fixed it. I'd been having so many problems with serializing I didnt notice
that this was a casting problem. The object deserialized wasnt the sort
expected. So i fixed that problem (previous developer had hardcoded some
file extensions) and the problem went away
thanks anyway
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top