0

.dwg ファイル内のブロック属性を一覧表示してデータベースに保存しようとしています。使用しているコードは次のとおりです。

using Autodesk.AutoCAD.DatabaseServices;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace CSP1257.Helpers
{
    public class AutocadHelper
    {

        public static Dictionary<string,string> ListAttributes(string dwgFile)
        {
            Dictionary<string, string> ret = new Dictionary<string, string>();

            using (Database attDb = new Database(false, true))
            {
                attDb.ReadDwgFile(dwgFile, FileShare.ReadWrite, false, null);
                Transaction tr = attDb.TransactionManager.StartTransaction();
                BlockTable bt = (BlockTable)attDb.BlockTableId.GetObject(OpenMode.ForRead);
                BlockTableRecord mBtr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);

                foreach (ObjectId msId in mBtr)
                {
                    BlockReference blkRef = (BlockReference)tr.GetObject(msId, OpenMode.ForRead);
                    AttributeCollection atts = blkRef.AttributeCollection;
                    if (atts == null)
                        continue;

                    foreach (ObjectId arId in atts)
                    {
                        AttributeReference attRef = (AttributeReference)tr.GetObject(arId, OpenMode.ForRead);
                        ret.Add(attRef.Tag, attRef.TextString);
                    }
                }
            }

            return ret;
        }
    }
}

ただし、次の例外が発生します。

Common Language Runtime detected an invalid program.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidProgramException: Common Language Runtime detected an invalid program.

Source Error:     
Line 20:                 Transaction tr = attDb.TransactionManager.StartTransaction();

なぜこの例外が発生するのかわかりませんが、同じ結果を達成する別の方法はありますか?

4

1 に答える 1