C# 程序集“Procotol, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”中的类型“ServerUser.ProcotolGame”

System.Runtime.Serialization.SerializationException

  HResult=0x8013150C

  Message=程序集“Procotol, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”中的类型“ServerUser.ProcotolGame”未标记为可序列化。

  Source=mscorlib

  StackTrace:

   在 System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)

   在 System.Runtime.Serialization.FormatterServices.<>c__DisplayClass9_0.b__0(MemberHolder _)

   在 System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)

   在 System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)

   在 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()

   在 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)

   在 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)

   在 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)

   在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)

   在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)

   在 ClientUser.ClientControl.Send(ProcotolGame game) 在 C:\Users\liuzhao\source\repos\ClientUser\ClientUser\ClientControl.cs 中: 第 51 行

   在 ClientUser.Program.Main(String[] args) 在 C:\Users\liuzhao\source\repos\ClientUser\ClientUser\Program.cs 中: 第 30 行

模型没有可序列化

在对应的模型类上添加

[Serializable]

如:
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerUser
{
    [Serializable]
    public  class ProcotolGame
    {
        //模块
        public int model;
        //操作
        public int one;
        //数据.附加信息
        public object data;
        public int ope;
    }
}

 

你可能感兴趣的:(c#)