не десериализуется класс

Общие вопросы о Unity3D

не десериализуется класс

Сообщение kelod 09 мар 2013, 00:02

есть клас, сериализуется и десериализуется на сервере отлично, а на клиенте выдаёт ошибку:
System.Runtime.Serialization.SerializationException: Field "Collection`1+items" not found in class CustomTree.Node+NodeCollection
at System.Runtime.Serialization.Formatters.Binary.ObjectReader. ReadTypeMetadata (System.IO.BinaryReader reader, Boolean isRuntimeObject, Boolean hasTypeInfo) [0x00000] in <filename unknown>:0
другие классы десериализируются отлично, даже классы с подкласами и вложениями
dll одна и на клиент и на сервер
если сериализацию делать на сервере, а потом на клиенте и сравнить результат, байты получаются разные

вот сам класс

Синтаксис:
Используется csharp
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace CustomTree
{
 
 
    /*  class Program
        {
            static void Main(string[] args)
            {
                var root = new Node("root");
                var c1 = root.AddNode("child1");
                var c2 = root.AddNode("child2");
                var c1_1 = c1.AddNode("child1_1");
                var c1_2 = c1.AddNode("child1_2");
                var c2_1 = new Node("child2_1");
                c2_1.Parent = c2;
                var c2_2 = c2.AddNode("child2_2");
                Console.Write(root.ToString());
                Console.WriteLine("\n");
                Console.WriteLine("Удаляем узлы\n");
                c2.Children.Remove(c2_2);
                c2_1.Parent = null;
                Console.WriteLine(root.ToString());
                Console.ReadKey();
            }
        }*/

    [Serializable]
    public class SomeClass
    {
        public List<Node> ListNode;
    }
 
 
    [Serializable]
    public class Node
    {
        public Node()
        {
            _children = new NodeCollection(this);
        }
 
        public Node(string name)
        {
            _children = new NodeCollection(this);
            this.Name = name;
        }
        public Node AddNode(string name)
        {
            var rv = new Node(name);
            this.Children.Add(rv);
            return rv;
        }
        Node _parent;
        public Node Parent
        {
            get
            {
                return _parent;
            }
            set
            {
                if (Parent != null || value == null)
                {
                    Parent.Children.Remove(this);
                }
                else
                {
                    value.Children.Add(this);
                }
                _parent = value;
            }
        }
        public string Name { get; set; }
        NodeCollection _children;
        public override string ToString()
        {
            var rv = new StringBuilder(Name);
            foreach (Node ch in Children)
            {
                SubNodeToString(ch, rv);
            }
            return rv.ToString();
        }
        public int Level
        {
            get
            {
                return Parent != null ? this.Parent.Level + 1 : 0;
            }
        }
        void SubNodeToString(Node n, StringBuilder sb)
        {
            sb.Append("\n" + repeat("\t", n.Level));
            sb.Append(n.Name);
            sb.Append(string.Format(" (Parent: {0})", n.Parent.Name));
            foreach (Node ch in n.Children)
            {
                SubNodeToString(ch, sb);
            }
        }
        string repeat(string s, int count)
        {
            var rv = new StringBuilder();
            for (int i = 0; i < count; i++) { rv.Append(s); };
            return rv.ToString();
        }
        public NodeCollection Children
        {
            get
            {
                return _children;
            }
            set { }//
        }
 
        [Serializable]
        public class NodeCollection : System.Collections.ObjectModel.Collection<Node>
        {
            public NodeCollection(Node owner)
            {
                _owner = owner;
            }
            Node _owner;
            protected override void InsertItem(int index, Node item)
            {
                if (!this.Contains(item))
                {
                    base.InsertItem(index, item);
                    item._parent = _owner;
                }
            }
            protected override void RemoveItem(int index)
            {
                this[index]._parent = null;
                base.RemoveItem(index);
            }
        }
    }
}
 
kelod
UNIт
 
Сообщения: 139
Зарегистрирован: 26 ноя 2012, 16:45

Вернуться в Общие вопросы

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 8