【C# OBD】OBD执行C#属性提取程序崩溃

我在OpenBuildings Designer软件中使用C#编写的程序获取构件属性,出现了程序崩溃的情况。程序的部分代码如下。经在Debug模式下调试,程序执行过程中会在foreach (IDgnECInstance inst in instCol)的位置出现程序崩溃。并且在调试过程中使用try...catch...捕获不到异常信息,程序会直接中断。这是一个偶发的现象,只对于部分的dgn文件会出现这种现象。一部分dgn文件可以正常获取到属性。如有需要,可以将文件发送到您的邮箱。

public void GetProperties(string strElemId, DgnModel dgnModel)
{
	string strInfo = "";
	ulong id;
	try
	{
		id = ulong.Parse(strElemId);
	}
	catch
	{
		strInfo = "未提供ElemId作为命令参数或提供的参数不合法";
		MessageCenter.Instance.ShowMessage(MessageType.Info, strInfo, strInfo, MessageAlert.None);
		return;
	}
	Element myElem = dgnModel.FindElementById((ElementId)id);
	if (null == myElem)
	{
		strInfo = "所提供ElemId无效";
		MessageCenter.Instance.ShowMessage(MessageType.Info, strInfo, strInfo, MessageAlert.None);
		return;
	}

	DgnECManager ecManager = DgnECManager.Manager;
	DgnECInstanceCollection instCol = ecManager.GetElementProperties(myElem, ECQueryProcessFlags.SearchAllClasses);
	try
	{
		foreach (IDgnECInstance inst in instCol)
		{
			if (inst == null)
				return;

			IECClass ecClass = inst.ClassDefinition;
			if (ecClass == null)
				return;

			IEnumerator<IECProperty> propertyEnum = inst.ClassDefinition.GetEnumerator();
			while (propertyEnum.MoveNext())
			{
				// 获取组
				if (propertyEnum.Current == null)
					continue;

				IECProperty prop = propertyEnum.Current;

				string displayLabel = "";
				int categoryPriority = 0;
				bool categoryDefaultExpand = false;
				Bentley.ECObjects.UI.ECPropertyPane.GetCategoryInformation(out displayLabel, out categoryPriority, out categoryDefaultExpand, prop, ecClass);

				// 获取属性名称及属性值
				if (propertyEnum.Current.Name == "")
					continue;

				IECPropertyValue propertyValue = inst.GetPropertyValue(propertyEnum.Current.Name);
				if (propertyValue == null)
					continue;

				if (propertyValue.IsNull)
					continue;

				if (propertyValue.IsArray)
				{
					IECArrayValue arrayVal = propertyValue as IECArrayValue;
					if (arrayVal.Count >= 1)
						propertyValue = arrayVal[0];
					else
						continue;
				}
				
				// 获取属性值
				string strName = propertyEnum.Current.DisplayLabel;
				string strVal = "";
				double dblVal = 0.0;
				
				// 下面的代码省略...
			}
		}
	}
	catch (Exception ex)
	{
		return;
	}
}