-1

I am trying to Serialize/Deserialize a object, but I am getting an "ArgumentException" on deserialization. My Object is this:

 public class Findoc
    {
        public Findoc()
        {

        }

        private string _ID = string.Empty;
        public string ID
        {
            get { return this._ID; }
            set { _ID = value; }
        }

        private int _lastindex;
        public int lastindex
        {
            get { return this._lastindex; }
            set { _lastindex = value; }
        }        

        private string _SilogiDate;
        public string SilogiDate
        {
            get { return this._SilogiDate; }
            set { _SilogiDate = value; }
        }

        private Truck _TR;
        public Truck TR
        {
            get { return this._TR; }
            set { _TR = value; }
        }

        private Routing _RT;
        public Routing RT
        {
            get { return this._RT; }
            set { _RT = value; }
        }

        private KentroKostous _KK;
        public KentroKostous KK
        {
            get { return this._KK; }
            set { _KK = value; }
        }

        private Busunit _BU;
        public Busunit BU
        {
            get { return this._BU; }
            set { _BU = value; }
        }

        private string _FINCODE = string.Empty;
        public string FINCODE
        {
            get { return this._FINCODE; }
            set { _FINCODE = value; }
        }

        private string _FINSTATE = "";
        public string FINSTATE
        {
            get { return this._FINSTATE; }
            set { _FINSTATE = value; }
        }

        private string _STAGE = "";
        public string STAGE
        {
            get { return this._STAGE; }
            set { _STAGE = value; }
        }

        private string _SPCS = "";
        public string SPCS
        {
            get { return this._SPCS; }
            set { _SPCS = value; }
        }

        private string _SPCSCODE = "";
        public string SPCSCODE
        {
            get { return this._SPCSCODE; }
            set { _SPCSCODE = value; }
        }


        private string _MTRSTS = "";
        public string MTRSTS
        {
            get { return this._MTRSTS; }
            set { _MTRSTS = value; }
        }

        private string _PARAGOMENO = "";
        public string PARAGOMENO
        {
            get { return this._PARAGOMENO; }
            set { _PARAGOMENO = value; }
        }

        private double _PARAGOMENOQTY1;
        public double PARAGOMENOQTY1
        {
            get { return this._PARAGOMENOQTY1; }
            set { _PARAGOMENOQTY1 = value; }
        }

        private double _PARAGOMENOQTY2;
        public double PARAGOMENOQTY2
        {
            get { return this._PARAGOMENOQTY2; }
            set { _PARAGOMENOQTY2 = value; }
        }

        private Boolean _PARAGOMENOUSESN;
        public Boolean PARAGOMENOUSESN
        {
            get { return this._PARAGOMENOUSESN; }
            set { _PARAGOMENOUSESN = value; }
        }

        private Boolean _EDITABLE = true;
        public Boolean EDITABLE
        {
            get { return this._EDITABLE; }
            set { _EDITABLE = value; }
        }

        private Boolean _ISPRINT;
        public Boolean ISPRINT
        {
            get { return this._ISPRINT; }
            set { _ISPRINT = value; }
        }

        private Boolean _ISCANCELED;
        public Boolean ISCANCELED
        {
            get { return this._ISCANCELED; }
            set { _ISCANCELED = value; }
        }

        private int _SOSOURCE;
        public int SOSOURCE
        {
            get { return this._SOSOURCE; }
            set { _SOSOURCE = value; }
        }

        private Series _series;
        public Series Series
        {
            get { return this._series; }
            set { _series = value; }
        }

        private string _TICK = string.Empty;
        public string TICK
        {
            get { return this._TICK; }
            set { _TICK = value; }
        }


        private string _COMMENTS = "";
        public string COMMEMTS
        {
            get { return this._COMMENTS; }
            set { _COMMENTS = value; }
        }

        private string _COMMENTS1 = "";
        public string COMMEMTS1
        {
            get { return this._COMMENTS1; }
            set { _COMMENTS1 = value; }
        }

        private string _COMMENTS2 = "";
        public string COMMEMTS2
        {
            get { return this._COMMENTS2; }
            set { _COMMENTS2 = value; }
        }             

        private string _karfoto_fincode = "";//gia tis eisprakseis
        public string Karfoto_fincode
        {
            get { return this._karfoto_fincode; }
            set { _karfoto_fincode = value; }
        }

        private List<Mtrline> _Mtrlines;
        public List<Mtrline> Mtrlines
        {
            get { return this._Mtrlines; }
            set { _Mtrlines = value; }
        }
    }

    public class SnLine
    {
        private string _TICK;
        public string TICK
        {
            get { return this._TICK; }
            set { _TICK = value; }
        }

        private string _sn;
        public string sn
        {
            get { return this._sn; }
            set { _sn = value; }
        }  
    }

    public class Mtrline
    {    
        public Mtrline(Findoc findoc)
        {
        }        

        private List<SnLine> _SnLines;
        public List<SnLine> SnLines
        {
            get { return this._SnLines; }
            set { _SnLines = value; }
        }

        private int _position;
        public int position
        {
            get { return this._position; }
            set { _position = value; }
        }

        private string _guid;
        public string guid
        {
            get { return this._guid; }
            set { _guid = value; }
        }

        private WhouseObj _Whouse1;
        public WhouseObj Whouse1
        {
            get { return this._Whouse1; }
            set { _Whouse1 = value; }
        }

        private WhouseObj _Whouse2;
        public WhouseObj Whouse2
        {
            get { return this._Whouse2; }
            set { _Whouse2 = value; }
        }

        private string _WHOUSE = "";
        public string WHOUSE
        {
            get { return this._WHOUSE; }

            set { _WHOUSE = value; }
        }

        private string _WHOUSESEC = "";
        public string WHOUSESEC
        {
            get { return this._WHOUSESEC; }

            set { _WHOUSESEC = value; }
        }

        private string _SPCS;
        public string SPCS
        {
            get { return this._SPCS; }
            set { _SPCS = value; }
        }

        private string _MPKCODE;
        public string MPKCODE
        {
            get { return this._MPKCODE; }
            set { _MPKCODE = value; }
        }

        private string _whousebin1remain;
        public string Whousebin1remain
        {
            get { return this._whousebin1remain; }
            set { _whousebin1remain = value; }
        }

        private string _whousebin2remain;
        public string Whousebin2remain
        {
            get { return this._whousebin2remain; }
            set { _whousebin2remain = value; }
        }

        private int _NEWLINE;
        public int NEWLINE
        {
            get { return this._NEWLINE; }
            set { _NEWLINE = value; }
        }

        private string _CCCPACK1;
        public string CCCPACK1
        {
            get {
                if (_CCCPACK1 == null)
                    return "";
                else
                    return this._CCCPACK1;
            }
            set { _CCCPACK1 = value; }
        }

        public string _CCCPACK2;
        public string CCCPACK2
        {
            get
            {
                if (_CCCPACK2 == null)
                    return "";
                else
                    return this._CCCPACK2;
            }
            set { _CCCPACK2 = value; }
        }
        private string _PAKETO = "";
        public string PAKETO
        {
            get { return this._PAKETO; }
            set { _PAKETO = value; }
        }

        private string _TICK;
        public string TICK
        {
            get { return this._TICK; }
            set { _TICK = value; }
        }     

        private string _AAA;
        public string AAA
        {
            get { return this._AAA; }
            set { _AAA = value; }
        }

        private MtrlModel _MTRL_Object;
        public MtrlModel MTRL_Object
        {
            get { return this._MTRL_Object; }
            set { _MTRL_Object = value; }
        }

        private double _SUMQTY; // SUMQTY ana eidos
        public double SUMQTY
        {
            get { return this._SUMQTY; }
            set { _SUMQTY = value; }
        }

        private double _SUMQTY2; // SUMQTY ana eidos
        public double SUMQTY2
        {
            get { return this._SUMQTY2; }
            set { _SUMQTY2 = value; }
        }

        private double _QTY; // posotita T
        public double QTY
        {
            get { return this._QTY; }
            set { _QTY = value; }
        }

        private double _QTY1;
        public double QTY1
        {
            get { return this._QTY1; }
            set { _QTY1 = value; }
        }

        private double _QTY2;
        public double QTY2
        {
            get { return this._QTY2; }
            set { _QTY2 = value; }
        }

        private double _QTYP;
        public double QTYP
        {
            get { return this._QTYP; }
            set { _QTYP = value; }
        }

        private string _FIELDS = "";
        public string FIELDS
        {
            get { return this._FIELDS; }
            set { _FIELDS = value; }
        }

        private string _COMMENTS = "";
        public string COMMENTS
        {
            get { return this._COMMENTS; }
            set { _COMMENTS = value; }
        }

        private string _COMMENTS1 = "";
        public string COMMENTS1
        {
            get { return this._COMMENTS1; }
            set { _COMMENTS1 = value; }
        }

        private string _COMMENTS2 = "";
        public string COMMENTS2
        {
            get { return this._COMMENTS2; }
            set { _COMMENTS2 = value; }
        }


        private CDIMLINE _CDIMNO1_Object;
        public CDIMLINE CDIMNO1_Object
        {
            get { return this._CDIMNO1_Object; }
            set { _CDIMNO1_Object = value; }
        }

        private string _CDIMNO1;
        public string CDIMNO1
        {
            get
            {
                if (this._CDIMNO1_Object != null)
                    return this._CDIMNO1_Object.NAME;
                else
                    return "";
            }
            set { _CDIMNO1 = value; }
        }

        private CDIMLINE _CDIMNO2_Object;
        public CDIMLINE CDIMNO2_Object
        {
            get { return this._CDIMNO2_Object; }
            set { _CDIMNO2_Object = value; }
        }

        private string _CDIMNO2;
        public string CDIMNO2
        {
            get
            {
                if (this._CDIMNO2_Object != null)
                    return this._CDIMNO2_Object.NAME;
                else
                    return "";
            }
            set { _CDIMNO2 = value; }
        }

        private CDIMLINE _CDIMNO3_Object;
        public CDIMLINE CDIMNO3_Object
        {
            get { return this._CDIMNO3_Object; }
            set { _CDIMNO3_Object = value; }
        }

        private string _CDIMNO3;
        public string CDIMNO3
        {
            get
            {
                if (this._CDIMNO3_Object != null)
                    return this._CDIMNO3_Object.NAME;
                else
                    return "";
            }
            set { _CDIMNO3 = value; }
        }

        private Lot _LOT;
        public Lot LOT
        {
            get { return this._LOT; }
            set { _LOT = value; }
        }       

        private string _CODE = "";
        public string CODE
        {
            get { return this._MTRL_Object.CODE; }
            set { _CODE = value; }
        }

        private string _MTRPLACE = "";
        public string MTRPLACE
        {
            get { return this._MTRL_Object.MTRPLACE; }
            set { _MTRPLACE = value; }
        }

        private double _SUMWHOUSE;
        public double SUMWHOUSE
        {
            get { return this._MTRL_Object.REMAIN; }
            set { _SUMWHOUSE = value; }
        }

        private double _WHOUSE_SERIES;
        public double WHOUSE_SERIES
        {
            get { return this._MTRL_Object.WHOUSE_SERIES_REMAIN; }
            set { _WHOUSE_SERIES = value; }
        }        

        private string _CODE1 = "";
        public string CODE1
        {
            get { return this._MTRL_Object.CODE1; }
            set { _CODE1 = value; }
        }

        private string _CODE2 = "";
        public string CODE2
        {
            get { return this._MTRL_Object.CODE2; }
            set { _CODE2 = value; }
        }

        private string _NAME = "";
        public string NAME
        {
            get { return this._MTRL_Object.NAME; }
            set { _NAME = value; }
        }

        private string _MTRL = "";
        public string MTRL
        {
            get { return this._MTRL_Object.MTRL; }
            set { _MTRL = value; }
        }

        private string _MTRUNIT1 = "";
        public string MTRUNIT1
        {
            get
            {
                if (this._MTRL_Object.MTRUNIT1 != null)
                    return this._MTRL_Object.MTRUNIT1.name;
                else
                    return "";
            }
            set { _MTRUNIT1 = value; }
        }

        private string _MTRUNIT2 = "";
        public string MTRUNIT2
        {
            get
            {
                if (this._MTRL_Object.MTRUNIT2 != null)
                    return this._MTRL_Object.MTRUNIT2.name;
                else
                    return "";
            }
            set { _MTRUNIT2 = value; }
        }

        private string _MTRUNIT3 = "";
        public string MTRUNIT3
        {
            get
            {
                if (this._MTRL_Object.MTRUNIT3 != null)
                    return this._MTRL_Object.MTRUNIT3.name;
                else
                    return "";
            }
            set { _MTRUNIT3 = value; }
        }

        private string _MTRUNIT4 = "";
        public string MTRUNIT4
        {
            get
            {
                if (this._MTRL_Object.MTRUNIT4 != null)
                    return this._MTRL_Object.MTRUNIT4.name;
                else
                    return "";
            }
            set { _MTRUNIT4 = value; }
        }

        private string _CRLOTCODE = "";
        public string CRLOTCODE
        {
            get { return this._CRLOTCODE; }        
            set { _CRLOTCODE = value; }
        }

        private string _CRLOTCODE1 = "";
        public string CRLOTCODE1
        {
            get { return this._CRLOTCODE1; }          
            set { _CRLOTCODE1 = value; }
        }

        private string _CRLOTCODE2 = "";
        public string CRLOTCODE2
        {
            get { return this._CRLOTCODE2; }          
            set { _CRLOTCODE2 = value; }
        }

        private string _CRLOTFDATE = "";
        public string CRLOTFDATE
        {
            get { return this._CRLOTFDATE; }
            set { _CRLOTFDATE = value; }
        }

        private string _SCANEDCODE = "";
        public string SCANEDCODE
        {
            get { return this._SCANEDCODE; }

            set { _SCANEDCODE = value; }
        }

        private Thesi _WHOUSEBIN1_Object;
        public Thesi WHOUSEBIN1_Object
        {
            get { return this._WHOUSEBIN1_Object; }
            set { _WHOUSEBIN1_Object = value; }
        }

        private string _WHOUSEBIN1;
        public string WHOUSEBIN1
        {
            get
            {
                if (this._WHOUSEBIN1_Object != null)
                    return this._WHOUSEBIN1_Object.name;
                else
                    return "";
            }
            set { _WHOUSEBIN1 = value; }
        }

        private Thesi _WHOUSEBIN2_Object;
        public Thesi WHOUSEBIN2_Object
        {
            get { return this._WHOUSEBIN2_Object; }
            set { _WHOUSEBIN2_Object = value; }
        }

        private string _WHOUSEBIN2;
        public string WHOUSEBIN2
        {
            get
            {
                if (this._WHOUSEBIN2_Object != null)
                    return this._WHOUSEBIN2_Object.name;
                else
                    return "";
            }
            set { _WHOUSEBIN2 = value; }
        }

        private double _ANAMENOMENA;
        public double ANAMENOMENA
        {
            get { return this._ANAMENOMENA; }
            set { _ANAMENOMENA = value; }
        }

        private string _FINCODE = "";
        public string FINCODE
        {
            get { return this._FINCODE; }
            set { _FINCODE = value; }
        }

        private string _FINDOC = "";
        public string FINDOC
        {
            get { return this._FINDOC; }
            set { _FINDOC = value; }
        }

        private string _SODTYPE = "";
        public string SODTYPE
        {
            get { return this._SODTYPE; }
            set { _SODTYPE = value; }
        }



        private string _STATUS = "";
        public string STATUS
        {
            get { return this._STATUS; }
            set { _STATUS = value; }
        }

        private string _AA = "";
        public string AA
        {
            get { return this._AA; }
            set { _AA = value; }
        }

        private string _GUARANTY_SNCODE = "";
        public string GUARANTY_SNCODE
        {
            get { return this._GUARANTY_SNCODE; }
            set { _GUARANTY_SNCODE = value; }
        }


    }

I serialize it with the following code:

string data = Newtonsoft.Json.JsonConvert.SerializeObject(UniversalModel.Parastatiko,Formatting.None , new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });

When I try to deserialize back to the object I get the exception error: ArgumentException. The code to deserialize is this.

  Findoc FFF = Newtonsoft.Json.JsonConvert.DeserializeObject<Findoc>(data, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); 

Any tips on what I am doing wrong?

HopAlongPolly
  • 1,347
  • 1
  • 20
  • 48
  • 5
    Seeing the full Argument exception may help indicate which argument caused this. – HopAlongPolly May 23 '18 at 13:31
  • Just to make things nicer looking you can remove all of the `private _*` variables. C# manages a private version for you when you are using the `{get; set; }` accessors. The answer to this question https://stackoverflow.com/questions/5096926/what-is-the-get-set-syntax-in-c from Josie Thompson does a great job of explaining. – HopAlongPolly May 23 '18 at 14:42
  • That FindDoc class is huge. Do all of the sub-classes really have to be subclasses. It's hard to tell but it looks like we are missing some of the class definitions as well. For example I saw some proerties that were type `CDIMLINE` but no class definition – HopAlongPolly May 23 '18 at 14:46
  • To maximize the chance that we can help you, we need to see a [mcve] of your problem that fully demonstrates the problem. Try to cut your classes down into something simple that still shows the problem. If you can't manage to do that, at least please [edit] your question to include the full `ToString()` output of the exception including the exception type, message, complete traceback and inner exception, if any. For more see [ask] and https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/ – dbc May 23 '18 at 19:49

1 Answers1

0

It may just be a typo in the question but separating the Serializer arguments on to their own lines shows you are passing a UniversalModel.Parastatiko in as the first argument...which I don't think is correct.

string data = Newtonsoft.Json.JsonConvert.SerializeObject(
    UniversalModel.Parastatiko,
    Formatting.None,
    new JsonSerializerSettings {
        NullValueHandling = NullValueHandling.Ignore
    }
);
HopAlongPolly
  • 1,347
  • 1
  • 20
  • 48