Cannot Bind to Target Method

Cannot Bind to Target Method

Anonymous
Not applicable
720 Views
1 Reply
Message 1 of 2

Cannot Bind to Target Method

Anonymous
Not applicable

I'm working on being able to serialize C# objects to AutoCAD entities. I have a method that serializes them and I'm trying to call this method from the AutoCAD command line intended to deserialize them.

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

However, when I call it, I'm greeted with this error and have no idea why as it gives no line numbers or useful debug information.

enter image description here

0 Likes
721 Views
1 Reply
Reply (1)
Message 2 of 2

CADbloke
Advocate
Advocate
F5? Did you run it in the debugger? What did you get when you clicked "Details"?
- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
0 Likes