Błąd serializacji podczas kopiowania i wklejania z elementu sterowania systemu Windows form w element zarządzania WPF

0

Pytanie

Mamy umożliwiają serializacji klasy, który zawiera dane ze schowka do transmisji z kontroli systemu Windows w element zarządzania WPF. To zadziałało w framework 4.8 po konwersji do .Net 5 teraz dostajemy błąd: Wpisz "System.RuntimeType" w złożeniu "System".Prywatne.CoreLib, Wersja=5.0.0.0, Kultura=neutralna, PublicKeyToken=7cec85d7bea7798e' nie jest oznaczony jako umożliwiają serializacji.

To się dzieje w module obsługi zdarzenia Drop w WPF w wierszu:

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

Gdzie "e" - jest to System.Windows.ДрагЕвентАрги.

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

Najlepsza odpowiedź

0

I to jest rozwiązanie problemu. W tym przypadku, na szczęście, właściwość TreeNode było niepotrzebne i można było dodać właściwość TypeName, aby z niego można było wyodrębnić typ.

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

W innych językach

Ta strona jest w innych językach

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