5

का कारण बनता है मैं कुछ कोड बनाने का प्रयास कर रहा हूं जो कक्षाओं की एक लाइब्रेरी को एक ऑटोकैड ड्राइंग में क्रमबद्ध और deserialize कर सकते हैं। इस सवाल के अलावा ऑटोकैड के साथ बहुत कुछ नहीं करना है क्योंकि मैं इसे सामान्य माध्यमों से डीबग नहीं कर सकता हूं। मैंने इस परियोजना को this article से शुरू किया और सफलतापूर्वक अपना कोड चलाने के लिए मिला। हालांकि जिस तरह से उसका कोड संरचित किया गया है, इसके लिए मुझे अपने सभी वर्गों को अपने बेसोबजेक्ट से प्राप्त करने की आवश्यकता होगी। चूंकि यह स्पष्ट रूप से एक कोड गंध है, मुझे पता था कि मुझे इसके बजाय एक इंटरफ़ेस बनाने की आवश्यकता है। नीचे वह कोड है जिसे मैंने समाप्त किया था।सीरियलाइजेशन कोड अनचाहे अपवाद

यह पहला खंड एक ऑटोकैड ड्राइंग में क्रमबद्ध करने के लिए जिम्मेदार कोड है।

[Serializable] 
public class MattMember: IClearspanSerializable 
{ 
    public string Name; 
    List<int> MattsInts; 


    public MattMember(string passedName, List<int> passedInts) 
    { 
     Name = passedName; 
     MattsInts = passedInts; 
    } 

    [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] 
    public void GetObjectData(SerializationInfo info, StreamingContext context) 
    { 
     info.AddValue("Name", Name); 
     info.AddValue("MattsInts", MattsInts); 
    } 

    [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] 
    public void SetObjectData(SerializationInfo info, StreamingContext context) 
    { 
     if (info == null) 
     { 
      throw new System.ArgumentNullException("info"); 
     } 
     Name = (string)info.GetValue("Name", typeof(string)); 

     MattsInts = (List<int>)info.GetValue("MattsInts", typeof(List<int>)); 
    } 


    void IClearspanSerializable.SetObjectData(object objectInDisguise) 
    { 


     if (objectInDisguise == null) 
     { 
      throw new System.ArgumentNullException("info"); 
     } 

     MattMember objectToCopy = (MattMember)objectInDisguise; 

     Name = objectToCopy.Name; 

     MattsInts = objectToCopy.MattsInts; 
    } 
} 

और यहाँ इंटरफेस है:

दूसरे खंड एक वर्ग का एक उदाहरण है कि मेरे कस्टम क्रमांकन इंटरफ़ेस

public class Commands 
{ 
    public class MyUtil 
    { 

     const int kMaxChunkSize = 127; 

     public ResultBuffer StreamToResBuf(MemoryStream ms, string appName) 
     { 

      ResultBuffer resBuf = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName, appName)); 

      for (int i = 0; i < ms.Length; i += kMaxChunkSize) 
      { 

       int length = (int)Math.Min(ms.Length - i, kMaxChunkSize); 

       byte[] datachunk = new byte[length]; 

       ms.Read(datachunk, 0, length); 

       resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataBinaryChunk, datachunk)); 
      } 

      return resBuf; 
     } 

     public MemoryStream ResBufToStream(ResultBuffer resBuf) 
     { 

      MemoryStream ms = new MemoryStream(); 

      TypedValue[] values = resBuf.AsArray(); 

      // Start from 1 to skip application name 

      for (int i = 1; i < values.Length; i++) 
      { 

       byte[] datachunk = (byte[])values[i].Value; 

       ms.Write(datachunk, 0, datachunk.Length); 

      } 

      ms.Position = 0; 

      return ms; 

     } 

     public void NewFromEntity(IClearspanSerializable objectToSave, Entity ent) 
     { 

      using (ResultBuffer resBuf = ent.GetXDataForApplication("Member")) 
      { 
       BinaryFormatter bf = new BinaryFormatter(); 

       bf.Binder = new MyBinder(); 

       MemoryStream ms = this.ResBufToStream(resBuf); 
       objectToSave.SetObjectData(bf.Deserialize(ms)); 
      } 

     } 


     public void SaveToEntity(IClearspanSerializable objectToSave, Entity ent) 
     { 

      // Make sure application name is registered 
      // If we were to save the ResultBuffer to an Xrecord.Data, 
      // then we would not need to have a registered application name 

      Transaction tr = ent.Database.TransactionManager.TopTransaction; 

      RegAppTable regTable = (RegAppTable)tr.GetObject(ent.Database.RegAppTableId, OpenMode.ForWrite); 

      if (!regTable.Has("Member")) 
      { 
       RegAppTableRecord app = new RegAppTableRecord(); 

       app.Name = "Member"; 

       regTable.Add(app); 

       tr.AddNewlyCreatedDBObject(app, true); 
      } 


      BinaryFormatter bf = new BinaryFormatter(); 
      MemoryStream ms = new MemoryStream(); 

      bf.Serialize(ms, objectToSave); 
      ms.Position = 0; 

      ent.XData = this.StreamToResBuf(ms, "Member");; 


     } 
    } 

    public sealed class MyBinder : SerializationBinder 
    { 
     public override Type BindToType(string assemblyName, string typeName) 
     { 
      return Type.GetType(string.Format("{0}, {1}", 

       typeName, assemblyName)); 
     } 
    } 


    [CommandMethod("SaveClassToEntityXData", CommandFlags.Modal)] 
    public void SaveClassToEntityXData(IClearspanSerializable objectToSerialize) 
    { 

     Database db = Application.DocumentManager.MdiActiveDocument.Database; 
     Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; 

     PromptEntityResult per = ed.GetEntity("Select entity to save class to:\n"); 

     if (per.Status != PromptStatus.OK) 
      return; 

     MyUtil util = new MyUtil(); 



     // Save it to the document 
     using (Transaction tr = db.TransactionManager.StartTransaction()) 
     { 

      Entity ent = (Entity)tr.GetObject(per.ObjectId, OpenMode.ForWrite); 

      util.SaveToEntity(objectToSerialize, ent); 

      tr.Commit(); 
     } 

     // Write some info about the results 

     //ed.WriteMessage("Content of MyClass we serialized:\n {0} \n", mc.ToString()); 

    } 


    [CommandMethod("GetClassFromEntityXData", CommandFlags.Modal)] 
    public void GetClassFromEntityXData(IClearspanSerializable objectToRestore) 
    { 

     Database db = Application.DocumentManager.MdiActiveDocument.Database; 
     Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; 

     MyUtil util = new MyUtil(); 

     PromptEntityResult per = ed.GetEntity("Select entity to get class from:\n"); 

     if (per.Status != PromptStatus.OK) 
      return; 

     // Get back the class 
     using (Transaction tr = db.TransactionManager.StartTransaction()) 
     { 
      Entity ent = (Entity)tr.GetObject(per.ObjectId, OpenMode.ForRead); 
      util.NewFromEntity(objectToRestore, ent); 

      tr.Commit(); 

     } 

    } 
} 

लागू करता है यहाँ एक डमी वर्ग के साथ मैं परीक्षण करने के लिए प्रयास कर रहा है :

public interface IClearspanSerializable 
{ 
    void GetObjectData(SerializationInfo info, StreamingContext context); 
    void SetObjectData(object objectInDisguise); 
} 

जब मैं ऑटोकैड के अंदर कोड चलाने का प्रयास करता हूं, तो मुझे यह त्रुटि मिलती है या। जो मुझे विश्वास दिलाता है कि मेरी कक्षाओं के आरंभ में एक साधारण बग है। मेरे ब्रेकपॉइंट्स में से कोई भी हिट नहीं मिलता है।

Unhandled Exception

मैं यह कैसे डिबग चाहिए? और मैंने अपना प्रारंभिकरण कहाँ खराब कर दिया है?

[संपादित करें], यहाँ क्या "विवरण" में है:

****************************************************************************** 
Application does not support just-in-time (JIT) 
debugging. See the end of this message for details. 

************** Exception Text ************** 
System.ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type. 
    at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure) 
    at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method) 
    at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction) 
    at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction) 
    at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction) 
    at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke() 


************** Loaded Assemblies ************** 
mscorlib 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18444 built by: FX451RTMGDR 
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll 
---------------------------------------- 
Acdbmgd 
    Assembly Version: 20.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/AcdbMgd.DLL 
---------------------------------------- 
adui20 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/adui20.DLL 
---------------------------------------- 
AdUiPalettes 
    Assembly Version: 20.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/AdUiPalettes.DLL 
---------------------------------------- 
WindowsBase 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsBase/v4.0_4.0.0.0__31bf3856ad364e35/WindowsBase.dll 
---------------------------------------- 
System 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll 
---------------------------------------- 
PresentationFramework 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.dll 
---------------------------------------- 
PresentationCore 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/PresentationCore/v4.0_4.0.0.0__31bf3856ad364e35/PresentationCore.dll 
---------------------------------------- 
System.Xaml 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xaml/v4.0_4.0.0.0__b77a5c561934e089/System.Xaml.dll 
---------------------------------------- 
System.Configuration 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll 
---------------------------------------- 
System.Xml 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll 
---------------------------------------- 
AdApplicationFrame 
    Assembly Version: 0.0.0.0 
    Win32 Version: 5.2.8.100 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/AdApplicationFrame.DLL 
---------------------------------------- 
AdWindows 
    Assembly Version: 5.2.10.200 
    Win32 Version: 5.2.10.200 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/AdWindows.DLL 
---------------------------------------- 
PresentationFramework.Classic 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.classic/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.classic.dll 
---------------------------------------- 
System.Drawing 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll 
---------------------------------------- 
accoremgd 
    Assembly Version: 20.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/accoremgd.DLL 
---------------------------------------- 
System.Core 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll 
---------------------------------------- 
Acmgd 
    Assembly Version: 20.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/Acmgd.DLL 
---------------------------------------- 
AcWindows 
    Assembly Version: 20.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/AcWindows.DLL 
---------------------------------------- 
AcWindows.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcWindows.resources.DLL 
---------------------------------------- 
AcCui 
    Assembly Version: 20.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/AcCui.DLL 
---------------------------------------- 
PresentationFramework-SystemXml 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemXml/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemXml.dll 
---------------------------------------- 
PresentationFramework.Aero 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Aero/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Aero.dll 
---------------------------------------- 
WindowsFormsIntegration 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsFormsIntegration/v4.0_4.0.0.0__31bf3856ad364e35/WindowsFormsIntegration.dll 
---------------------------------------- 
System.Windows.Forms 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll 
---------------------------------------- 
PresentationUI 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationUI/v4.0_4.0.0.0__31bf3856ad364e35/PresentationUI.dll 
---------------------------------------- 
System.Xml.Linq 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll 
---------------------------------------- 
PresentationFramework-SystemXmlLinq 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemXmlLinq/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemXmlLinq.dll 
---------------------------------------- 
FeaturedAppsPlugin 
    Assembly Version: 20.0.0.0 
    Win32 Version: 20.0.46.0.0 
    CodeBase: file:///C:/ProgramData/Autodesk/ApplicationPlugins/Autodesk%20FeaturedApps.bundle/Contents/Windows/2015/Win32/FeaturedAppsPlugin.dll 
---------------------------------------- 
UIAutomationTypes 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationTypes/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationTypes.dll 
---------------------------------------- 
PresentationFramework-SystemCore 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemCore/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemCore.dll 
---------------------------------------- 
Anonymously Hosted DynamicMethods Assembly 
    Assembly Version: 0.0.0.0 
    Win32 Version: 4.0.30319.18444 built by: FX451RTMGDR 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/mscorlib/v4.0_4.0.0.0__b77a5c561934e089/mscorlib.dll 
---------------------------------------- 
AcLayer 
    Assembly Version: 20.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/AcLayer.DLL 
---------------------------------------- 
AcLayer.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcLayer.resources.DLL 
---------------------------------------- 
AcAeNet.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcAeNet.resources.DLL 
---------------------------------------- 
AcCloudRender.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcCloudRender.resources.DLL 
---------------------------------------- 
AcCustomize.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcCustomize.resources.DLL 
---------------------------------------- 
AcDxWizard.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcDxWizard.resources.DLL 
---------------------------------------- 
AcExportLayoutUI.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcExportLayoutUI.resources.DLL 
---------------------------------------- 
AcInterfere.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcInterfere.resources.DLL 
---------------------------------------- 
AcLayerTools.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcLayerTools.resources.DLL 
---------------------------------------- 
AcMrUi.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcMrUi.resources.DLL 
---------------------------------------- 
AcMultiLineUi.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcMultiLineUi.resources.DLL 
---------------------------------------- 
AcRecoverAll.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcRecoverAll.resources.DLL 
---------------------------------------- 
AcScaleList.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcScaleList.resources.DLL 
---------------------------------------- 
AcUnderlay.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcUnderlay.resources.DLL 
---------------------------------------- 
AcViewTransitionsUi.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcViewTransitionsUi.resources.DLL 
---------------------------------------- 
AdskConnectionPointMgd.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AdskConnectionPointMgd.resources.DLL 
---------------------------------------- 
AcCalcUi.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcCalcUi.resources.DLL 
---------------------------------------- 
AcLivePreviewContext 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/AcWindows.dll 
---------------------------------------- 
AcDialogToolTips 
    Assembly Version: 20.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/AcDialogToolTips.DLL 
---------------------------------------- 
AcDialogToolTips.resources 
    Assembly Version: 0.0.0.0 
    Win32 Version: 20.0.51.0.0 
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202015/en-US/AcDialogToolTips.resources.DLL 
---------------------------------------- 
Write To Block 
    Assembly Version: 1.0.5276.26438 
    Win32 Version: 1.0.0.0 
    CodeBase: file:///C:/Users/Administrator/Documents/Clearspan/AutoCAD%20Projects/Write%20To%20Block/Write%20To%20Block/bin/Debug/Write%20To%20Block.dll 
---------------------------------------- 

************** JIT Debugging ************** 
Application does not support Windows Forms just-in-time (JIT) 
debugging. Contact the application author for more 
information. 
+0

विवरण बटन पर क्लिक करें पहले और बाद के लिए विवरण पर चिपकाएं। मुझे आश्चर्य है कि इस सवाल को 5 अपवॉट क्यों प्राप्त हुए ..... – Matt

+0

ऑटोकैड का कौन सा संस्करण/साक्षात्कार यह है? –

+0

यह 32-बिट विंडोज 7 मशीन –

उत्तर

1

System.ArgumentException: लक्ष्य विधि से आबद्ध नहीं किया जा सकता, क्योंकि इसके हस्ताक्षर या सुरक्षा पारदर्शिता प्रतिनिधि प्रकार के साथ संगत नहीं है।

मेरी समझ यह है कि आपके इंटरफ़ेस की "GetObjectData" विधि BinnaryFormatter रसोई में कहीं भी ISerializable एक के साथ संघर्ष करती है।

बस अपने MyUtil में सभी रूपांतरण समारोह (StreamToResBuf, ResBufToStream ...) refactor और आप को क्रमानुसार/deserialize [Serializable] विशेषता के साथ चिह्नित किसी भी वर्ग में सक्षम होना चाहिए।
आपका डमी वर्ग इस तरह दिखना चाहिए (संग्रह और आदिम प्रकार ऑटो क्रमांकित हैं, केवल आवश्यकता ISerializable लागू):

[Serializable] 
public class MattMember 
{ 
    public string Name; 
    List<int> MattsInts; 
} 

NewFromEntity विधि (यहाँ किसी भी अनावश्यक डाली बचने के लिए):

public object NewFromEntity(Entity ent) 
     {  
      using (ResultBuffer resBuf = ent.GetXDataForApplication("Member")) 
      { 
       BinaryFormatter bf = new BinaryFormatter(); 

       bf.Binder = new MyBinder(); 

       MemoryStream ms = this.ResBufToStream(resBuf); 
       return bf.Deserialize(ms); 
      }  
     } 

और अंत में अपने आदेश:

[CommandMethod("GetClassFromEntityXData", CommandFlags.Modal)] 
//Updated return type here but don't know if it is correct with AutoCAD 
public object GetClassFromEntityXData() 
{ 
    Database db = Application.DocumentManager.MdiActiveDocument.Database; 
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; 
    object objectToRestore; 

    MyUtil util = new MyUtil(); 

    PromptEntityResult per = ed.GetEntity("Select entity to get class from:\n"); 

    if (per.Status != PromptStatus.OK) 
     return; 

    // Get back the class 
    using (Transaction tr = db.TransactionManager.StartTransaction()) 
    { 
     Entity ent = (Entity)tr.GetObject(per.ObjectId, OpenMode.ForRead); 
     //Cast to your IClearspan interface here, or use Reflection 
     // to determine deserialized object's Type 
     objectToRestore = util.NewFromEntity(ent); 

     tr.Commit(); 
    } 

    return objectToRestore; 
} 
0

अंधेरे में शॉट:

public MattMember() 
{ 

} 

: के बाद से किसी और अपने वस्तु constucts आप या तो एक डिफ़ॉल्ट निर्माता की जरूरत या इस तरह के एक विशेष deseralization- निर्माता:

protected MattMember(SerializationInfo info, StreamingContext context) 
    { 
// Set object data  
    } 

शायद आपके इंटरफेस को भी ISerializable

+0

पर ऑटोकैड 2015 है धन्यवाद, लेकिन मैंने उन सभी को भी आजमाया है –

1
at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure) 
    at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method) 
    at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction) 

स्टैक ट्रेस को सही ढंग से समझना महत्वपूर्ण है। आपके द्वारा पोस्ट किए गए कोड में से कोई भी शामिल नहीं है, यह कभी शुरू नहीं हुआ। यह विफल रहा है जब ऑटोकैड अपने आदेश हैंडलर कॉल करने की कोशिश:

[CommandMethod("GetClassFromEntityXData", CommandFlags.Modal)] 
public void GetClassFromEntityXData(IClearspanSerializable objectToRestore) 
// etc.. 

ऑटोकैड आप देने के लिए कि objectToRestore तर्क, यह आपके इंटरफ़ेस के बारे में सेम पता नहीं है नहीं जा रहा है। अपवाद का अर्थ क्या है, यह एक रहस्य तर्क के साथ एक विधि को एक प्रतिनिधि को बांध नहीं सकता है। ध्यान दें कि आपके द्वारा शुरू किया गया उदाहरण कोड तर्क के बिना एक विधि का उपयोग करता है। और उपयोगकर्ता ने ड्रॉइंग एंट्री लेने के लिए संपादक को अनुमति देने के लिए Editor.GetEntity() का उपयोग कैसे किया। मुझे लगता है कि आपको एक समान योजना की आवश्यकता है, मुझे ऑटोकैड स्क्रिप्टिंग के बारे में पर्याप्त जानकारी नहीं है।

0
[CommandMethod("SaveClassToEntityXData", CommandFlags.Modal)] 
public void SaveClassToEntityXData(IClearspanSerializable objectToSerialize) 

कमांड लागू करने वाला फ़ंक्शन पैरामीटर स्वीकार नहीं कर सकता है, लेकिन कमांड कार्यान्वयन के अंदर आप कमांड लाइन इनपुट फ़ंक्शन जैसे GetString(), GetInteger() इत्यादि का उपयोग करके पैरामीटर स्वीकार कर सकते हैं जो कि संपादक वर्ग के अंतर्गत पाए जा सकते हैं।

से http://adndevblog.typepad.com/autocad/2012/07/create-command-with-parameters.html

संबंधित मुद्दे