[CONNECT C#] LoadRootModelById crashes MicroStation.

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
            }
        }
   }
 }

Parents Reply Children
No Data