Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Exception reading a Diagram from a stream (Read 4845 times)
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 126
Location: England
Joined: Oct 23rd, 2006
Exception reading a Diagram from a stream
Oct 28th, 2015 at 2:38pm
Print Post  
A client is having problems reading a file created with our software. I'm reading a Diagram from a stream as follows:

try
{
using (Stream stream = new FileStream(pathname, FileMode.Open, FileAccess.Read, FileShare.Read))
{
flowChart.LoadFromStream(stream);

// read other data
.
.
}
}

catch(Exception ex)
{
// Exception caught as follows:
// End of stream encountered before parsing was completed
}

I'm getting an exception thrown from the LoadFromStream function. I don't have the source code for FlowChart .NET. Is there a diagnostic I can use see what went wrong? Other files created with the same version of the software are reading fine.

Regards
DavidL
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception reading a Diagram from a stream
Reply #1 - Oct 28th, 2015 at 3:14pm
Print Post  
"End of stream encountered before parsing was completed" message seems to be associated with .NET's BinaryFormatter class. We use BinaryFormatter for serialization of Tag/Id custom objects, and for properties of controls hosted in ControlNodes. Are you using any of them? I suppose you might get the exception if the tags' ISerializable implementation format changed after that file was created. In such case you could fix the file by temporary switching the deserialization code to old format, and resaving in new one.

Or perhaps the file is corrupted, e.g. the process or OS might have crashed before the file stream was flushed completely. If you attach the file we could extract some parts of it that were saved successfully.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 126
Location: England
Joined: Oct 23rd, 2006
Re: Exception reading a Diagram from a stream
Reply #2 - Oct 28th, 2015 at 5:00pm
Print Post  
Stoyan

I don't use ControlNodes but each ShapeNode does have a Tag attached.  They have not been changed recently, but when they are changed I don't delete any fields and new fields are only ever added at the end of the class.  I also think that the file was saved and then read with the same version of the software, but I'm checking on this now.

File is too big to attach. Can I email it directly?

DavidL
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception reading a Diagram from a stream
Reply #3 - Oct 28th, 2015 at 6:07pm
Print Post  
Please email it to support@mindfusion.eu along with Tag class definition.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception reading a Diagram from a stream
Reply #4 - Oct 29th, 2015 at 10:30am
Print Post  
Our developer traced through the deserialization code, the last thing it tries to do is load a BoxDataL tag value for ShapeNode with ZIndex = 1269. At that point the binary formatter reaches the end of the stream. If you look at the end of the file using VS hex editor you will see it cuts off abruptly at the position of some type descriptor for a string (perhaps for the Swim_Agent field). The List<int> field before it was loaded successfully.



Our guess is that either there was a full-disk condition when saving, or some transfer / download hasn't completed successfully if your customers exchange files by email or http. Also from your code it seems you write additional values into the stream; if you use the stream.Seek method check if there isn't some chance for it to return current position to a point inside diagram's data.

All data up to that point is well formatted, and from the 3000 diagram items in the file about 2850 were read successfully. If the customer doesn't have a backup we might try to extract them for you. Swimlane information and some groups are missing from the file too.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 126
Location: England
Joined: Oct 23rd, 2006
Re: Exception reading a Diagram from a stream
Reply #5 - Nov 1st, 2015 at 10:41am
Print Post  
If you could re-create as much of the file as possible, that would save our customer a lot of work.  They don't seem to have a working backup.

Many thanks
DavidL
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception reading a Diagram from a stream
Reply #6 - Nov 2nd, 2015 at 12:41pm
Print Post  
This build adds a TryLoadCorruptedFile method that should let you load the file in your application:
https://mindfusion.eu/_beta/fcnet634.zip

Otherwise you would not be able to load tag values from file saved by us as their types will be defined in a different assembly (our test project). That method manages to load 2242 nodes and their text and tag values.

Unfortunately, the information for ConnectionPoint objects used to connect nodes to links is missing from the file you sent us, along with control point coordinates, so the loaded DiagramLink objects aren't of much use. If you have some Tag values associated with links that will help you identify target nodes, try reassigning links' Origin and Destination values. If you store some kind of parent-node identifiers in nodes' Tags, you could delete the unconnected links and create new ones from parent to child nodes.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 126
Location: England
Joined: Oct 23rd, 2006
Re: Exception reading a Diagram from a stream
Reply #7 - Nov 2nd, 2015 at 5:00pm
Print Post  
Stoyan
Thanks, that has helped a lot. As you have said the chart is not great, but the tags contain data that will allow the customer to re-create the file.

Thanks again
DavidL
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint