gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 10:32:08 25 4
gpt4 key购买 nike

我正在努力将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com