La serializzazione di errore quando si copia e incolla da un controllo windows form un controllo WPF

0

Domanda

Abbiamo una classe serializzabile la detiene i dati dagli appunti di passare da windows da controllo a controllo WPF. Questo ha funzionato nel quadro 4.8 dopo la conversione .Netto 5 ora ottenere il messaggio di errore: Tipo 'System.RuntimeType' in Assembly 'System.Privato.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' non è contrassegnato come serializzabile.

Questo si verifica nel gestore dell'evento Drop in WPF sulla linea:

var tClip = e.Data.GetDataPresent(typeof(ClipboardDescriptor));

Dove " e " è il Sistema.Windows.DragEventArgs.

using System;
using System.Windows.Forms;

namespace Support.Classes
{
    /// <summary>
    /// Summary description for ClipboardDescriptor.
    /// </summary>
    [Serializable]
    public class ClipboardDescriptor
    {
        private Guid id;
        private Guid parentDocumentID;
        private System.Type objtype;
        private TreeNode baseTreeNode;
        private string objname;

        public ClipboardDescriptor()
        {
            baseTreeNode = null;
        }

        public Guid ParentDocumentID
        {
            get { return(parentDocumentID); }
            set { parentDocumentID = value; }
        }

        public Guid ID
        {
            get { return(id); }
            set { id = value; }
        }

        public System.Type ObjType
        {
            get { return(objtype); }
            set { objtype = value; }
        }

        public string ObjName
        {
            get { return(objname); }
            set { objname = value; }
        }

        /// <summary>
        /// Get the treenode that this object is associated with
        /// </summary>
        public TreeNode BaseTreeNode
        {
            get { return(baseTreeNode); }
            set { baseTreeNode = value; }
        }
    }
}
.net-5 c# wpf
2021-11-22 21:52:28
1

Migliore risposta

0

Questo è il fix. In questo caso per fortuna TreeNode proprietà era inutile e TypeName proprietà può essere aggiunto in modo che il Tipo potrebbe essere recuperato da esso.

using System;

namespace JMPT.Support.Classes
{
    /// <summary>
    /// Summary description for ClipboardDescriptor.
    /// </summary>
    [Serializable]
    public class ClipboardDescriptor
    {
        public Guid ParentDocumentID { get; set; }
        public Guid ID { get; set; }
        [field: NonSerialized]
        public Type ObjType { get; set; }
        public string ObjName { get; set; }
        public string ObjTypeName { get; set; }
    }
}
  
2021-11-23 16:59:35

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................