C# 无法绑定(bind)到目标方法

标签 c# autocad autocad-plugin

我正在努力将 C# 对象序列化为 AutoCAD 实体。我有一个方法可以序列化它们,我正在尝试从 AutoCAD 命令行调用此方法来反序列化它们。

            [CommandMethod("OpenXRecord", CommandFlags.Modal)]
            public SerializeTest XMLOpen()
            {
                Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;
                Database db = doc.Database;
                SerializeTest retval = null;
                XmlSerializer serializer = new XmlSerializer(typeof(SerializeTest));
                using (Transaction tr = db.TransactionManager.StartTransaction())
                using (DocumentLock docLock = doc.LockDocument())
                {
                    PromptSelectionResult acSSPrompt = ed.GetSelection();
                    if (acSSPrompt.Status == PromptStatus.OK)
                    {
                        ObjectId[] ids = acSSPrompt.Value.GetObjectIds();
                        Entity acadObj = tr.GetObject(ids[0], OpenMode.ForWrite) as Entity;
                        if (acadObj == null || acadObj.ExtensionDictionary == ObjectId.Null)
                        {
                            tr.Abort();
                            return retval;
                        }
                        using (DBDictionary dict = tr.GetObject(acadObj.ExtensionDictionary, OpenMode.ForRead, false) as DBDictionary)
                        {
                            if (dict.Contains("KW_PID"))
                            {
                                using (Xrecord xrec = tr.GetObject(dict.GetAt("KW_PID"), OpenMode.ForRead) as Xrecord)
                                {
                                    if (xrec != null)
                                    {
                                        using (ResultBuffer rb = xrec.Data)
                                        {
                                            if (rb != null)
                                            {
                                                using (MemoryStream stream = new MemoryStream())
                                                {
                                                    TypedValue[] tvs = rb.AsArray();
                                                    if (tvs != null)
                                                    {
                                                        if (tvs[0].TypeCode == (short)DxfCode.Text)
                                                        {
                                                            string xmlString = "";
                                                            TextWriter writer = new StreamWriter(stream);
                                                            for (int i = 1; i < tvs.Length; i++)
                                                            {
                                                                if (tvs[i].TypeCode == (short)DxfCode.Text)
                                                                {
                                                                    xmlString = (string)tvs[i].Value; writer.Write(xmlString);
                                                                }
                                                            }
                                                            writer.Flush();
                                                            stream.Position = 0;
                                                            retval = serializer.Deserialize(stream) as SerializeTest;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return retval;
            }

但是,当我调用它时,我遇到了这个错误,并且不知道为什么,因为它没有提供行号或有用的调试信息。

enter image description here

最佳答案

明白了,该方法必须为 void,否则它会生气并抛出此错误。

关于C# 无法绑定(bind)到目标方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29679853/

相关文章:

c# - ProtectedData.用户更改密码后取消保护

c# - 如何捕获 AutoCAD.NET 中抛出的未处理异常

c# - C# 中的 "using"- 从 using 语句中调用的辅助函数是否使用包含的 IDisposable 对象?

xml - 设置 .xml 以在 AutoCAD 启动时加载 .dvb 插件

unit-testing - 在第三方软件 API (AutoCAD) 上进行单元测试的最佳实践

lisp - 顺序执行LISP中的多个命令

visual-studio-2010 - Visual Studio 2010 中使用 Entity Framework 4.1 面向 x64 平台

c# - 使用嵌套数组进行 LINQ to JSON 查询的正确语法

c# - 在 C# 3.0 中缩小 XML 的最佳方法

c# - Web 客户端使用下载文件从服务器抓取文件 - 处理异常