1

データを転送するには、XmlSerializer を使用しています。しかし、次の行で実行時エラーが発生します。

XmlSerializer serializer = new XmlSerializer(typeof(Packets.Wrapper));

エラーは「追加情報: タイプ 'Packets.Wrapper' を反映するエラー」です。MSDN によると、空のコンストラクターを使用する必要がありますが、エラーは修正されません。

クラスは次のようになります。

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace Packets
{
    [Serializable]
    public class Wrapper
    {
        int _sID = 0;
        int _sSession = 0;
        PacketType _sType = PacketType.None;
        AuthRequest _sAuthRequest = null;
        AuthResponse _sAuthResponse = null;
        ProxyRequest _sProxyRequest = null;
        ProxyResponse _sProxyResponse = null;

        public Wrapper()
        {

        }

        public int ID
        {
            get { return _sID; }
            set { _sID = value; }
        }

        public int Session
        {
            get { return _sSession; }
            set { _sSession = value; }
        }

        public PacketType Type
        {
            get { return _sType; }
            set { _sType = value; }
        }

        public AuthRequest AuthRequest
        {
            get { return _sAuthRequest; }
            set { _sAuthRequest = value; }
        }

        public AuthResponse AuthResponse
        {
            get { return _sAuthResponse; }
            set { _sAuthResponse = value; }
        }

        public ProxyRequest ProxyRequest
        {
            get { return _sProxyRequest; }
            set { _sProxyRequest = value; }
        }

        public ProxyResponse ProxyResponse
        {
            get { return _sProxyResponse; }
            set { _sProxyResponse = value; }
        }
    }

    [Serializable]
    public enum PacketType
    {
        AuthRequest,
        AuthResponse,
        ProxyRequest,
        ProxyResponse,
        None
    }

    [Serializable]
    public enum AuthResult
    {
        Accepted,
        Denied,
        Error
    }

    [Serializable]
    public enum ProxyAction
    {
        Send,
        Response,
        Connect,
        Close
    }

    [Serializable]
    public enum ProxyResult
    {
        Connected,
        Sent,
        Revieved,
        Error
    }

    [Serializable]
    public class AuthRequest
    {
        string username = null;
        string password = null;

        public AuthRequest()
        {

        }

        public string Username
        {
            get { return username; }
            set { username = value; }
        }

        public string Password
        {
            get { return password; }
            set { password = value; }
        }
    }

    [Serializable]
    public class AuthResponse
    {
        AuthResult authResult = AuthResult.Denied;

        public AuthResponse()
        {

        }

        public AuthResult AuthResult
        {
            get { return authResult; }
            set { authResult = value; }
        }
    }

    [Serializable]
    public class ProxyRequest
    {
        ProxyAction _sAction;
        string _sIP = null;
        int _sPort = 0;
        TcpClient _sClient = null;

        public ProxyRequest()
        {

        }

        public ProxyAction Action
        {
            get { return _sAction; }
            set { _sAction = value; }
        }

        public string IP
        {
            get { return _sIP; }
            set { _sIP = value; }
        }

        public int Port
        {
            get { return _sPort; }
            set { _sPort = value; }
        }

        public TcpClient Client
        {
            get { return _sClient; }
            set { _sClient = value; }
        }
    }

    [Serializable]
    public class ProxyResponse
    {
        public ProxyResult _sResult = ProxyResult.Error;
        public StringBuilder _sError = new StringBuilder();
        public StringBuilder _sRecieved = new StringBuilder();
        public TcpClient _sClient = null;

        public ProxyResponse()
        {

        }

        public ProxyResult Result
        {
            get { return _sResult; }
            set { _sResult = value; }
        }

        public StringBuilder Error
        {
            get { return _sError; }
            set { _sError = value; }
        }

        public StringBuilder Recieved
        {
            get { return _sRecieved; }
            set { _sRecieved = value; }
        }

        public TcpClient Client
        {
            get { return _sClient; }
            set { _sClient = value; }
        }
    }
}

お時間をいただきありがとうございます。

4

1 に答える 1

0

わかった。TcpClient はシリアル化できません。

于 2013-03-23T13:33:02.603 に答える