diff --git a/CADShared/Runtime/DBTrans.cs b/CADShared/Runtime/DBTrans.cs index 38af048c03807e3c600dbdac1a6e8a73f7d3b6b8..441baeb8f08c4b80ce6b3e5338acbf7c67a4f0b5 100644 --- a/CADShared/Runtime/DBTrans.cs +++ b/CADShared/Runtime/DBTrans.cs @@ -250,16 +250,26 @@ public DBTrans(string fileName, if (doc is null) { Database = new Database(false, true); - if (Path.GetExtension(_fileName).ToLower().Contains("dxf")) + try { - Database.DxfIn(_fileName, null); + if (Path.GetExtension(_fileName).ToLower().Contains("dxf")) + { + Database.DxfIn(_fileName, null); + } + else + { + Database.ReadDwgFile(_fileName, fileOpenMode, true, password); + } } - else + catch { - Database.ReadDwgFile(_fileName, fileOpenMode, true, password); + IsDisposed = true; // 读取出错造成未能 push, 固这里设为 true + throw new ArgumentException($"文件 [{fileName}] 的格式版本可能高于当前CAD版本,读取错误!"); + } + finally + { + Database.CloseInput(true); } - - Database.CloseInput(true); } else {