My Application has been working for a while now. but a user informed me that it was causing MicroStation to crash. the application is using the workset location and searches for other files and gets data from the other files. i was able to pinpoint where the crash was happening. basically there was a dgn file in the workset that is corrupt (couldn't even open it manually).
the code opens the file like the example code below. it has no problem loading the file but it crashes MicroStation when i call the curfile.LoadRootModelById() line. Even if i wrap it in a try catch it still crashes MicroStation. i know corrupted files are rare but i would like to make my app not crash and catch this error but dont see how. any thoughts? should i submit this as a bug in the sdk . the out param for the status should return false rather then crashing the program..
DgnDocument dgndoc = BD.DgnDocument.CreateForLocalFile(curinitialFile.localpath); DgnFileOwner fileowner = BD.DgnFile.Create(dgndoc, BD.DgnFileOpenMode.ReadOnly); DgnFile curfile = fileowner.DgnFile; StatusInt openstatus; curfile.LoadDgnFile(out openstatus); if (openstatus != BD.StatusInt.Success || curfile.IsLoaded == false) { //failed to open } else { //load all sheet models ModelIndexCollection collection = curfile.GetModelIndexCollection(); IEnumerator<ModelIndex> models = collection.GetEnumerator(); StatusInt statusloadedmodel; while (models.MoveNext()) { if (models.Current.ModelType == BD.DgnModelType.Sheet) { curfile.LoadRootModelById(out statusloadedmodel, models.Current.Id); if (statusloadedmodel == BD.StatusInt.Success) { //loaded model } else { //failed to load model } } } }
Hi John,
John Drsek said:basically there was a dgn file in the workset that is corrupt (couldn't even open it manually).
What happens when you try to open this file in MicroStation as normal file manually? MicroStation rejects the file, it crashes or something else?
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
it hangs on the loading and then i get the MicroStation has stopped working dialog. so it is crashing on open.
but in the code it returns sucess for loading the files and i can even enumerate the models. (there is a sheet model and a drawing model).
the crash doesnt happen untill i try to load the sheet model in my code.
i uploaded the corrupted file below.
/cfs-file/__key/communityserver-discussions-components-files/343173/110412_5F00_MP304.dgn
im thinking i dont have a way to catch this error to prevent the crash
John Drsek said:it hangs on the loading and then i get the MicroStation has stopped working dialog. so it is crashing on open.
When MicroStation hangs and crashes, I think you cannot assume that SDK will not.
John Drsek said:but in the code it returns sucess for loading the files and i can even enumerate the models.
It's not in conflict with MicroStation behavior in my opinion. Whereas in SDK the steps are done explicitly (create file, open it, load model, load dictionaries), MicroStation does all of them automatically.
Things like loading DGN or iterating model indexes do not require to read the whole data, but indexes only, so the file error does not appear.
John Drsek said:i uploaded the corrupted file below.
I can open the file without any problem. Using MicroStation CE Update 14, English version, on Windows 10 Czech, fully updated.
John Drsek said:im thinking i dont have a way to catch this error to prevent the crash
To catch internal MicroStation exceptions can be implemented on application domain level. But often such exception means that MicroStation is in undefined state anyway, so the only correct solution is to close the session.
Jan Šlegr said:I can open the file without any problem.
I see that the drawing model contains unresolved reference. Maybe the problem is in that file, not in the shared file itself?
Regards,
Jan Šlegr said:Maybe the problem is in that file, not in the shared file itself?
When the problem is in the reference, what will happen when you will change your code to:
curfile.LoadRootModelById(out statusLoadedModel, modelIndex.Id, true, false, false);
... and to try what will happen when you will change the last 2 arguments back to true independently?
Answer Verified By: John Drsek
yes when i move the file and open it manually so it cant find the relative path to the reference is does then open. so i think your right, the problem might be the reference.
when i try the additional parameters here are results
false, false = status is successful
true, false = crashes
false, true = status is successful
true, true = crashes
John Drsek said:so i think your right, the problem might be the reference.
The question is whether the problem is in the reference file itself or in the attachment definition. I see the reference is Cached, so maybe something wrong is with the visible edges cache in that file?
John Drsek said:when i try the additional parameters here are results
It confirms that the problem happens when the reference is loaded, because when the first argument is false, it works ... and this argument is "load references".
A question now is whether you need to load the references or not ;-)
I don't need to load the references...
as always thanks for the help.