How do I resolve CS1941 Error in LINQ, C# - c#

I am trying this query but it gives me CS1941 Error.
Image of error:
ReportList = from hb in (new XPQuery<HallBanquet>(das.UOW))
join hbi in (new XPQuery<HallBanquetItem>(das.UOW)) on hb.DocId equals hbi.HallBanquet
join cus in (new XPQuery<Customer>(das.UOW)) on hb.Customer equals cus.MastId
select new
{
hb.DocId,
hb.Site,
hb.DocNo,
hb.RefNo,
hb.DocDt,
hb.Customer,
hb.NoOfPax,
hb.PartyDate,
hb.FromTime,
hb.ToTime,
hb.MainMenu,
hb.OfferPackage,
hb.Currency,
hb.CurRate,
hb.LPONo,
hb.LPODate,
hb.ExpectedDeliveryDt,
hb.RoundOff,
hb.SubTotal,
hb.NetAmount,
hb.Remarks,
hbi.SeqNo,
hbi.HallBanquet,
hbi.ItemType,
hbi.Code,
Desc = hbi.Description,
hbi.Item,
hbi.Pkg,
hbi.Unit,
hbi.Qty,
hbi.Price,
hbi.Cost,
hbi.DiscountPer,
hbi.DiscountAmt,
hbi.Amount,
hbi.TotalAmt,
hbi.IsInclussiveTax,
hbi.TaxCd,
hbi.TaxPer,
hbi.TaxAmt,
hbi.GlCode,
cus.Description
};
The error is thrown on the second line at join
HallBanquet Class :
public class HallBanquet : Epimonos.BizObjects.Core.XPDocumentObject
{
public HallBanquet(Session session) : base(session)
{
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public override void AfterConstruction()
{
base.AfterConstruction();
// Place here your initialization code.
}
public override void Initialize(RstUser LoginUser, RstSite LoginSite)
{
}
public override void AfterDisplay(RstUser LoginUser, RstSite LoginSite)
{
UpdateTotals();
}
private Customer _Customer;
[RValidate("Customer", true, 0)]
public Customer Customer
{
get { return _Customer; }
set {
SetPropertyValue<Customer>(nameof(Customer), ref _Customer, value);
if (!IsLoading && !IsSaving)
{
this.Branch = null;
this.Contact = null;
//this.Currency = GetCompanyCurrency(this.Site.Company);
this.Currency = Site?.Company?.CompanyCurrencies.FirstOrDefault(e => e.Currency == this.Customer?.Currency);
}
}
}
private CustomerBranch _Branch;
[RValidate("Branch", false, 0)]
public CustomerBranch Branch
{
get { return _Branch; }
set
{
SetPropertyValue<CustomerBranch>(nameof(Branch), ref _Branch, value);
if (!IsLoading && !IsSaving)
{
this.Contact = null;
}
}
}
private CustomerContact _Contact;
[RValidate("Contact",false,0)]
public CustomerContact Contact
{
get { return _Contact; }
set { SetPropertyValue<CustomerContact>(nameof(Contact), ref _Contact, value); }
}
private string _ContactTel;
public string ContactTel
{
get { return _ContactTel; }
set { SetPropertyValue<string>(nameof(ContactTel), ref _ContactTel, value); }
}
private decimal _NoOfPax;
[RValidate("NoOfPax", true, 0)]
public decimal NoOfPax
{
get { return _NoOfPax; }
set { SetPropertyValue<decimal>(nameof(NoOfPax), ref _NoOfPax, value); }
}
private DateTime _PartyDate = DateTime.Today;
public DateTime PartyDate
{
get { return _PartyDate; }
set { SetPropertyValue<DateTime>(nameof(PartyDate), ref _PartyDate, value); }
}
private DateTime _FromTime = DateTime.Parse("12:00");
public DateTime FromTime
{
get { return _FromTime; }
set { SetPropertyValue<DateTime>(nameof(FromTime), ref _FromTime, value); }
}
private DateTime _ToTime=DateTime.Parse("12:00");
public DateTime ToTime
{
get { return _ToTime; }
set { SetPropertyValue<DateTime>(nameof(ToTime), ref _ToTime, value); }
}
private FoodPkg _MainMenu;
[RValidate("MainMenu", true, 0)]
public FoodPkg MainMenu
{
get { return _MainMenu; }
set { SetPropertyValue<FoodPkg>(nameof(MainMenu), ref _MainMenu, value); }
}
private string _OfferPackage;
[Size(50)]
public string OfferPackage
{
get { return _OfferPackage; }
set { SetPropertyValue<string>(nameof(OfferPackage), ref _OfferPackage, value); }
}
private RstCompanyCurrency _Currency;
[RValidate("Currency", true, 0 )]
public RstCompanyCurrency Currency
{
get { return _Currency; }
set { SetPropertyValue<RstCompanyCurrency>(nameof(Currency), ref _Currency, value);
if (!IsLoading && !IsSaving)
{
this.CurRate = value == null ? 0 : value.CurRate;
}
}
}
private Double _CurRate;
[CustomValidation(typeof(VcCommon), "ValidateCurrencyRate")]
public Double CurRate
{
get { return _CurRate; }
set { SetPropertyValue<Double>(nameof(CurRate), ref _CurRate, value); }
}
private string _LPONo;
[Size(50)]
[RValidate("LPO No", false ,50 )]
public string LPONo
{
get { return _LPONo; }
set { SetPropertyValue<string>(nameof(LPONo), ref _LPONo, value); }
}
private DateTime _LPODate = DateTime.Today;
public DateTime LPODate
{
get { return _LPODate; }
set { SetPropertyValue<DateTime>(nameof(LPODate), ref _LPODate, value); }
}
private DateTime _ExpectedDeliveryDt;
public DateTime ExpectedDeliveryDt
{
get { return _ExpectedDeliveryDt; }
set { SetPropertyValue<DateTime>(nameof(ExpectedDeliveryDt), ref _ExpectedDeliveryDt, value); }
}
private Decimal _CustomerBalance;
[NonPersistent]
public Decimal CustomerBalance
{
get { return _CustomerBalance; }
set { SetPropertyValue<Decimal>(nameof(CustomerBalance), ref _CustomerBalance, value); }
}
private Decimal _RoundOff;
[CustomValidation(typeof(VcCommon), "ValidateRoundOff")]
public Decimal RoundOff
{
get { return _RoundOff; }
set { SetPropertyValue<Decimal>(nameof(RoundOff), ref _RoundOff, value);
UpdateTotals();
}
}
private Decimal _SubTotal;
public Decimal SubTotal
{
get { return _SubTotal; }
set { SetPropertyValue<Decimal>(nameof(SubTotal), ref _SubTotal, value); }
}
private Decimal _NetAmount;
public Decimal NetAmount
{
get { return _NetAmount; }
set { SetPropertyValue<Decimal>(nameof(NetAmount), ref _NetAmount, value); }
}
private string _Remarks;
[Size(SizeAttribute.Unlimited)]
public string Remarks
{
get { return _Remarks; }
set { SetPropertyValue<string>(nameof(Remarks), ref _Remarks, value); }
}
[DevExpress.Xpo.Association("HallBanquet-Item"), Aggregated()]
public XPCollection<HallBanquetItem> HallBanquetItems
{
get
{
XPCollection<HallBanquetItem> col = GetCollection<HallBanquetItem>(nameof(HallBanquetItems));
if (col.Sorting.Count == 0)
{
col.Sorting.Add(new DevExpress.Xpo.SortProperty("SeqNo", SortingDirection.Ascending));
}
return col;
}
}
public void UpdateTotals()
{
if (IsLoading || IsSaving) return;
Decimal netAmt = 0;
Decimal taxAmt = 0;
foreach (var item in this.HallBanquetItems)
{
if (!item.IsDeleting)
{
netAmt += item.TotalAmt;
}
}
_NetAmount = CommonFx.Round((netAmt + this.RoundOff), this.Currency?.Currency);
_SubTotal = CommonFx.Round((netAmt-taxAmt), this.Currency?.Currency);
}
}
HallBanquetItem Class (Child Table)
public class HallBanquetItem : XPDocumentDet
{
public HallBanquetItem(Session session) : base(session)
{
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public override void AfterConstruction()
{
base.AfterConstruction();
// Place here your initialization code.
}
private HallBanquet _HallBanquet;
[Association("HallBanquet-Item")]
public HallBanquet HallBanquet
{
get { return _HallBanquet; }
set { SetPropertyValue<HallBanquet>(nameof(HallBanquet), ref _HallBanquet, value); }
}
private RstConstants _ItemType;
public RstConstants ItemType
{
get { return _ItemType; }
set { SetPropertyValue<RstConstants>(nameof(ItemType), ref _ItemType, value);
ItmTypeDs = value?.Description;
}
}
private string ItmTypeDs { get; set; }
private string _Code;
[Size(50)]
//[RValidate("Code", true, 50)]
public string Code
{
get { return _Code; }
set { SetPropertyValue<string>(nameof(Code), ref _Code, value); }
}
private string _Description;
[Size(200)]
//[RValidate("Description", true, 200)]
public string Description
{
get { return _Description; }
set { SetPropertyValue<string>(nameof(Description), ref _Description, value); }
}
private Guid _Item;
public Guid Item
{
get { return _Item; }
set { SetPropertyValue<Guid>(nameof(Item), ref _Item, value);
}
}
private float _Pkg = 1;
public float Pkg
{
get { return _Pkg; }
set
{
SetPropertyValue<float>(nameof(Pkg), ref _Pkg, value);
}
}
private string _Unit;
[Size(50)]
//[RValidate("Unit", true,50 )]
public string Unit
{
get { return _Unit; }
set { SetPropertyValue<string>(nameof(Unit), ref _Unit, value); }
}
private Decimal _Qty = 1;
public Decimal Qty
{
get { return _Qty; }
set
{
SetPropertyValue<Decimal>(nameof(Qty), ref _Qty, value);
SetTaxAndSalesAmount();
}
}
private Decimal _Price;
public Decimal Price
{
get { return _Price; }
set
{
SetPropertyValue<Decimal>(nameof(Price), ref _Price, value);
SetTaxAndSalesAmount();
}
}
private float _Cost;
public float Cost
{
get { return _Cost; }
set { SetPropertyValue<float>(nameof(Cost), ref _Cost, value); }
}
private Decimal _DiscountPer;
public Decimal DiscountPer
{
get { return _DiscountPer; }
set
{
SetPropertyValue<Decimal>(nameof(DiscountPer), ref _DiscountPer, value);
this.DiscountAmt = Math.Round(((Price * Qty) * value) / 100, 3, MidpointRounding.AwayFromZero);
}
}
private Decimal _DiscountAmt;
public Decimal DiscountAmt
{
get { return _DiscountAmt; }
set
{
SetPropertyValue<Decimal>(nameof(DiscountAmt), ref _DiscountAmt, value);
SetTaxAndSalesAmount();
}
}
private Decimal _Amount;
public Decimal Amount
{
get { return _Amount; }
set { SetPropertyValue<Decimal>(nameof(Amount), ref _Amount, value); }
}
private Decimal _TotalAmt;
public Decimal TotalAmt
{
get { return _TotalAmt; }
set { SetPropertyValue<Decimal>(nameof(TotalAmt), ref _TotalAmt, value); }
}
private Boolean _IsInclussiveTax;
public Boolean IsInclussiveTax
{
get { return _IsInclussiveTax; }
set { SetPropertyValue<Boolean>(nameof(IsInclussiveTax), ref _IsInclussiveTax, value); }
}
private Tax _TaxCd;
public Tax TaxCd
{
get { return _TaxCd; }
set
{
SetPropertyValue<Tax>(nameof(TaxCd), ref _TaxCd, value);
this.TaxPer = value == null ? 0 : value.TaxValue;
}
}
private Decimal _TaxPer;
public Decimal TaxPer
{
get { return _TaxPer; }
set
{
SetPropertyValue<Decimal>(nameof(TaxPer), ref _TaxPer, value);
SetTaxAndSalesAmount();
}
}
private Decimal _TaxAmt;
public Decimal TaxAmt
{
get { return _TaxAmt; }
set { SetPropertyValue<Decimal>(nameof(TaxAmt), ref _TaxAmt, value); }
}
private Account _GlCode;
public Account GlCode
{
get { return _GlCode; }
set { SetPropertyValue<Account>(nameof(GlCode), ref _GlCode, value); }
}
private void SetTaxAndSalesAmount()
{
if (!IsLoading && !IsSaving)
{
this.TaxAmt = Math.Round(CommonFx.GetTaxAmount(this.IsInclussiveTax, this.TaxPer, ((this.Price * this.Qty) - this.DiscountAmt)), 3);
this.Amount = Math.Round(CommonFx.GetTaxableAmount(this.IsInclussiveTax, this.TaxPer, ((this.Price * this.Qty) - this.DiscountAmt)), 3);
this.TotalAmt = Math.Round(CommonFx.GetAmountWithTax(this.IsInclussiveTax, this.TaxPer, ((this.Price * this.Qty) - this.DiscountAmt)), 3);
}
}
}
Customer Tabe
public class Customer : Epimonos.BizObjects.Core.XPMasterObject
{
public Customer(Session session) : base(session)
{
// This constructor is used when an object is loaded from a persistent storage.
// Do not place any code here.
}
public override void AfterConstruction()
{
base.AfterConstruction();
// Place here your initialization code.
}
public override void Initialize(RstUser LoginUser, RstSite LoginSite)
{
_VATRegion = VATRegion.Domestic;
}
public override void AfterDisplay(RstUser LoginUser, RstSite LoginSite)
{
///Value assigned after display
}
#region Properties
private string _ShortDs;
[Size(10)]
[RValidate("Short Description",true ,10 )]
public string ShortDs
{
get { return _ShortDs; }
set { SetPropertyValue<string>(nameof(ShortDs), ref _ShortDs, value); }
}
private CustomerGroup _Parent;
public CustomerGroup Parent
{
get { return _Parent; }
set { SetPropertyValue<CustomerGroup>(nameof(Parent), ref _Parent, value); }
}
private RstCurrency _Currency;
public RstCurrency Currency
{
get { return _Currency; }
set { SetPropertyValue<RstCurrency>(nameof(Currency), ref _Currency, value); }
}
private string _IDNumber;
[Size(50)]
[RValidate("ID. Number",false , 50)]
public string IDNumber
{
get { return _IDNumber; }
set { SetPropertyValue<string>(nameof(IDNumber), ref _IDNumber, value); }
}
private string _CustomerType;
[Size(30)]
[RValidate("CustomerType",false, 30)]
public string CustomerType
{
get { return _CustomerType; }
set { SetPropertyValue<string>(nameof(CustomerType), ref _CustomerType, value); }
}
[NonPersistent]
private RstBaseType _BaseType;
public RstBaseType BaseType
{
get { return _BaseType; }
set { SetPropertyValue<RstBaseType>(nameof(BaseType), ref _BaseType, value); }
}
private VATRegion _VATRegion;
public VATRegion VATRegion
{
get { return _VATRegion; }
set { SetPropertyValue<VATRegion>(nameof(VATRegion), ref _VATRegion, value); }
}
private string _VATNumber;
[Size(50)]
[RValidate("VAT Number",false , 50)]
public string VATNumber
{
get { return _VATNumber; }
set { SetPropertyValue<string>(nameof(VATNumber), ref _VATNumber, value); }
}
private DateTime _VATStartDt;
public DateTime VATStartDt
{
get { return _VATStartDt; }
set { SetPropertyValue<DateTime>(nameof(VATStartDt), ref _VATStartDt, value); }
}
private DateTime _ContractExpiry = DateTime.Today;
public DateTime ContractExpiry
{
get { return _ContractExpiry; }
set { SetPropertyValue<DateTime >(nameof(ContractExpiry), ref _ContractExpiry, value); }
}
private bool _ShowPriceInDN;
public bool ShowPrice
{
get { return _ShowPriceInDN; }
set { SetPropertyValue<bool>(nameof(ShowPrice), ref _ShowPriceInDN, value); }
}
/// <summary>
/// Mannual blocking of Customer from Transaction
/// </summary> _BlockCustomer
private bool _BlockCustomer;
public bool BlockCustomer
{
get { return _BlockCustomer; }
set { SetPropertyValue<bool>(nameof(BlockCustomer), ref _BlockCustomer, value);
if (!IsLoading && !IsSaving && !BlockCustomer) _BlockedReason = "";
}
}
private string _BlockedReason;
[Size(100)]
[RValidate("Blocked Reason",false ,100 )]
public string BlockedReason
{
get { return _BlockedReason; }
set { SetPropertyValue<string>(nameof(BlockedReason), ref _BlockedReason, value); }
}
private string _PaymentTerms;
[Size(30)]
[RValidate("Payment Terms",false , 30)]
public string PaymentTerms
{
get { return _PaymentTerms; }
set { SetPropertyValue<string>(nameof(PaymentTerms), ref _PaymentTerms, value); }
}
private string _DeliveryTerms;
[Size(30)]
[RValidate("DeliveryTerms",false , 30)]
public string DeliveryTerms
{
get { return _DeliveryTerms; }
set { SetPropertyValue<string>(nameof(DeliveryTerms), ref _DeliveryTerms, value); }
}
private Account _CustomerLedger;
public Account CustomerLedger
{
get { return _CustomerLedger; }
set { SetPropertyValue<Account>(nameof(CustomerLedger), ref _CustomerLedger, value); }
}
private Account _AdvanceLedger;
public Account AdvanceLedger
{
get { return _AdvanceLedger; }
set { SetPropertyValue<Account>(nameof(AdvanceLedger), ref _AdvanceLedger, value); }
}
private Boolean _IsSubCustomer;
public Boolean IsSubCustomer
{
get { return _IsSubCustomer; }
set
{
SetPropertyValue<Boolean>(nameof(IsSubCustomer), ref _IsSubCustomer, value);
if (!IsLoading && !IsSaving && !IsSubCustomer) _ParentCustomer = null;
}
}
private Customer _ParentCustomer;
public Customer ParentCustomer
{
get { return _ParentCustomer; }
set { SetPropertyValue<Customer>(nameof(ParentCustomer), ref _ParentCustomer, value); }
}
private bool _IsCreditLimitCheck;
public bool IsCreditLimitCheck
{
get { return _IsCreditLimitCheck; }
set
{
SetPropertyValue<bool>(nameof(IsCreditLimitCheck), ref _IsCreditLimitCheck, value);
if (!IsCreditLimitCheck)
{
_CreditPeriod = 0;
_CreditLimit = 0;
}
}
}
private int _CreditPeriod;
public int CreditPeriod
{
get { return _CreditPeriod; }
set { SetPropertyValue<int>(nameof(CreditPeriod), ref _CreditPeriod, value); }
}
private Decimal _CreditLimit;
public Decimal CreditLimit
{
get { return _CreditLimit; }
set { SetPropertyValue<Decimal>(nameof(CreditLimit), ref _CreditLimit, value); }
}
private SalesMan _SalesMan;
public SalesMan SalesMan
{
get { return _SalesMan; }
set { SetPropertyValue<SalesMan>(nameof(SalesMan), ref _SalesMan, value); }
}
#endregion
#region Associations
[Association("Customer-CustomerBranch")]
public XPCollection<CustomerBranch> CustomerBranches
{
get
{
XPCollection<CustomerBranch> col = GetCollection<CustomerBranch>(nameof(CustomerBranches));
if (col.Sorting.Count == 0)
{
col.Sorting.Add(new DevExpress.Xpo.SortProperty("SeqNo", SortingDirection.Ascending));
}
return col;
}
}
private XPCollection<CustomerBranch> _ActiveBranches;
public XPCollection<CustomerBranch> ActiveBranches
{
get
{
return _ActiveBranches;
}
}
[Association("Customer-CustomerContact")]
public XPCollection<CustomerContact> CustomerContacts
{
get
{
XPCollection<CustomerContact> col = GetCollection<CustomerContact>(nameof(CustomerContacts));
if (col.Sorting.Count == 0)
{
col.Sorting.Add(new DevExpress.Xpo.SortProperty("SeqNo", SortingDirection.Ascending));
}
return col;
}
}
public XPCollection<CustomerContact> ActiveCustContacts(Guid? BranchID)
{
if (BranchID != null)
{
return new XPCollection<CustomerContact>(this.Session, CriteriaOperator.Parse($"Customer = '{this.MastId}'AND Active AND CustomerBranch.RowId='{BranchID}' "),
new SortProperty("SeqNo", SortingDirection.Ascending));
}
else
{
return new XPCollection<CustomerContact>(this.Session, CriteriaOperator.Parse($"Customer = '{this.MastId}'AND Active"),
new SortProperty("SeqNo", SortingDirection.Ascending));
}
}
#endregion
}

Probably, in the 2nd line you should write hb.DocId equals hbi.HallBanquetId or hb.DocId equals hbi.DocId instead of hb.DocId equals hbi.HallBanquet (It depends on how your foreign key pointing from item to banquet is named).

Related

json DeserializeObject ArgumentException

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?
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
}
);

Json data deserialzation returning null value for a property

private static int DefaultApiClientTimeout = 30;
public WorkItemDetail GetWorkItemDetail(
int userNumber, int userNumberExternal, string applicationId,
short computerNumber, DateTime wiDate, int wiSequence,
int wiDetailSequence, bool includeImage)
{
string uri = string.Format("api/work-item-detail?userNumber={0}&userNumberExternal={1}&applicationId={2}&computerNumber={3}&wiDate={4}&wiSequence={5}&wiDetailSequence={6}&includeImage={7}", userNumber, userNumberExternal, applicationId, computerNumber, wiDate, wiSequence, wiDetailSequence, includeImage);
WorkItemDetail result = ProcessRequest<object, WorkItemDetail>(uri, "GET", null);
return result;
}
public ResponseType ProcessRequest<RequestType, ResponseType>(
string uri,
string method = "GET",
RequestType reqtype = default(RequestType))
where RequestType : new()
{
var result = ProcessRequest<RequestType>(uri, method, reqtype);
return JsonConvert.DeserializeObject<ResponseType>(result);
}
public string ProcessRequest<RequestType>(
string uri,
string method = "GET",
RequestType reqtype = default(RequestType))
where RequestType : new()
{
var request = CreateWebRequest(uri, method);
var x = (HttpWebResponse)request.GetResponse(); //the exception :(
var strResult = new StreamReader(x.GetResponseStream()).ReadToEnd();
return strResult;
}
public WebRequest CreateWebRequest(string uri, string method = "GET")
{
string url = "http://localhost:3144/" + uri;
var request = WebRequest.Create(url);
request.ContentType = "application/json; charset=utf-8";
request.Method = method;
//Convert minutes to milliseconds.
request.Timeout = DefaultApiClientTimeout * 60000;
return request;
}
above is my entire code.
I have a problem in deserialzing jsondata. from my web api method data is returning correctly but when coming to client result i.e., above code while deserializing jsondata ImageInBytes property is getting null.
[Serializable]
public class WorkItemDetail : IWorkItemKey
{
private byte[] thumbnailImage;
private byte[] image;
private short wiDetailSequence;
private string workItemDetailType;
private int networkShare;
private string networkSharePath;
private string filePath;
private string displayImageFileName;
private string imagePath;
private DateTime workItemDate;
private string documentOcr;
#region Work Item Members
/// <summary>
/// This will actually be a ShortDate from the database
/// </summary>
public DateTime WorkItemDate
{
get { return workItemDate; }
set { workItemDate = value; }
}
private int wiSequence;
public int WISequence
{
get { return wiSequence; }
set { wiSequence = value; }
}
public short WIDetailSequence
{
get { return wiDetailSequence; }
set { wiDetailSequence = value; }
}
private short _otherSideWIDetailSequence;
public short OtherSideWIDetailSequence
{
get { return _otherSideWIDetailSequence; }
set { _otherSideWIDetailSequence = value; }
}
private string sourceType;
public string SourceType
{
get { return sourceType; }
set { sourceType = value; }
}
private string sourceIdentifier;
public string SourceIdentifier
{
get { return sourceIdentifier; }
set { sourceIdentifier = value; }
}
#endregion
private int _reason;
public int Reason
{
get { return _reason; }
set { _reason = value; }
}
private short _computerNumber;
public short ComputerNumber
{
get { return _computerNumber; }
set { _computerNumber = value; }
}
private string _computerName;
public string ComputerName
{
get { return _computerName; }
set { _computerName = value; }
}
private DateTime? _WIDateDest;
public DateTime? WIDateDest
{
get { return _WIDateDest; }
set { _WIDateDest = value; }
}
private int? _WISequenceDest;
public int? WISequenceDest
{
get { return _WISequenceDest; }
set { _WISequenceDest = value; }
}
private short? _WIDetailSequenceDest;
public short? WIDetailSequenceDest
{
get { return _WIDetailSequenceDest; }
set { _WIDetailSequenceDest = value; }
}
private short? _OtherSideWIDetailSequenceDest;
public short? OtherSideWIDetailSequenceDest
{
get { return _OtherSideWIDetailSequenceDest; }
set { _OtherSideWIDetailSequenceDest = value; }
}
public string WorkItemDetailType
{
get { return workItemDetailType; }
set { workItemDetailType = value; }
}
public int NetworkShare
{
get { return networkShare; }
set { networkShare = value; }
}
public string NetworkSharePath
{
get { return networkSharePath; }
set { networkSharePath = value; }
}
public string FilePath
{
get { return filePath; }
set { filePath = value; }
}
public string DisplayImageFileName
{
get { return displayImageFileName; }
set { displayImageFileName = value; }
}
public string ImagePath
{
get { return imagePath; }
set { imagePath = value; }
}
public byte[] ImageInBytes
{
get { return image; }
set { image = value; }
}
public byte[] ThumbnailImage
{
get { return thumbnailImage; }
set { thumbnailImage = value; }
}
private string ocrData;
public string OCRData
{
get { return ocrData; }
set { ocrData = value; }
}
private string _userName;
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
private bool? _isCorrespondence;
public bool? IsCorrespondence
{
get { return _isCorrespondence; }
set { _isCorrespondence = value; }
}
private bool? isCorrespondenceDBValue;
public bool? IsCorrespondenceDBValue
{
get { return isCorrespondenceDBValue; }
set { isCorrespondenceDBValue = value; }
}
private Guid? wfInstanceId;
public Guid? WFInstanceId
{
get { return wfInstanceId; }
set { wfInstanceId = value; }
}
private DateTime _transactionTime;
public DateTime TransactionTime
{
get { return _transactionTime; }
set { _transactionTime = value; }
}
private DateTime _endTime;
public DateTime EndTime
{
get { return _endTime; }
set { _endTime = value; }
}
private string _transactionType;
public string TransactionType
{
get { return _transactionType; }
set { _transactionType = value; }
}
private string _applicationId;
public string ApplicationId
{
get { return _applicationId; }
set { _applicationId = value; }
}
private string _applicationName;
public string ApplicationName
{
get { return _applicationName; }
set { _applicationName = value; }
}
private bool isFront;
public bool IsFront
{
get { return isFront; }
set { isFront = value; }
}
private int _userNumber;
public int UserNumber
{
get { return _userNumber; }
set { _userNumber = value; }
}
private string barcode1;
public string BarCode1
{
get { return barcode1; }
set { barcode1 = value; }
}
private string barcode2;
public string BarCode2
{
get { return barcode2; }
set { barcode2 = value; }
}
private string barcode3;
public string BarCode3
{
get { return barcode3; }
set { barcode3 = value; }
}
private string barcode4;
public string BarCode4
{
get { return barcode4; }
set { barcode4 = value; }
}
private string barcode5;
public string BarCode5
{
get { return barcode5; }
set { barcode5 = value; }
}
private bool? markSense1;
public bool? MarkSense1
{
get { return markSense1; }
set { markSense1 = value; }
}
private bool? markSense2;
public bool? MarkSense2
{
get { return markSense2; }
set { markSense2 = value; }
}
private bool? markSense3;
public bool? MarkSense3
{
get { return markSense3; }
set { markSense3 = value; }
}
private bool? markSense4;
public bool? MarkSense4
{
get { return markSense4; }
set { markSense4 = value; }
}
private bool? markSense5;
public bool? MarkSense5
{
get { return markSense5; }
set { markSense5 = value; }
}
private bool? markSense6;
public bool? MarkSense6
{
get { return markSense6; }
set { markSense6 = value; }
}
private bool? markSense7;
public bool? MarkSense7
{
get { return markSense7; }
set { markSense7 = value; }
}
private bool? markSense8;
public bool? MarkSense8
{
get { return markSense8; }
set { markSense8 = value; }
}
private bool? markSense9;
public bool? MarkSense9
{
get { return markSense9; }
set { markSense9 = value; }
}
private bool? markSense10;
public bool? MarkSense10
{
get { return markSense10; }
set { markSense10 = value; }
}
private string data;
public string Data
{
get { return data; }
set { data = value; }
}
private string auditTrail;
public string AuditTrail
{
get { return auditTrail; }
set { auditTrail = value; }
}
private short? displayImageHorizontalPixels;
public short? DisplayImageHorizontalPixels
{
get { return displayImageHorizontalPixels; }
set { displayImageHorizontalPixels = value; }
}
private short? displayImageVerticalPixels;
public short? DisplayImageVerticalPixels
{
get { return displayImageVerticalPixels; }
set { displayImageVerticalPixels = value; }
}
private short? displayImageHorizontalResolution;
public short? DisplayImageHorizontalResolution
{
get { return displayImageHorizontalResolution; }
set { displayImageHorizontalResolution = value; }
}
private short? displayImageVerticalResolution;
public short? DisplayImageVerticalResolution
{
get { return displayImageVerticalResolution; }
set { displayImageVerticalResolution = value; }
}
private byte? displayImageColorDepth;
public byte? DisplayImageColorDepth
{
get { return displayImageColorDepth; }
set { displayImageColorDepth = value; }
}
private int displayImageBytes;
public int DisplayImageBytes
{
get { return displayImageBytes; }
set { displayImageBytes = value; }
}
private byte[] displayImageMD5Hash;
public byte[] DisplayImageMD5Hash
{
get { return displayImageMD5Hash; }
set { displayImageMD5Hash = value; }
}
private string iclImageFileName;
public string ICLImageFileName
{
get { return iclImageFileName; }
set { iclImageFileName = value; }
}
private short? iCLImageHorizontalPixels;
public short? ICLImageHorizontalPixels
{
get { return iCLImageHorizontalPixels; }
set { iCLImageHorizontalPixels = value; }
}
private short? iCLImageVerticalPixels;
public short? ICLImageVerticalPixels
{
get { return iCLImageVerticalPixels; }
set { iCLImageVerticalPixels = value; }
}
private short? iCLImageHorizontalResolution;
public short? ICLImageHorizontalResolution
{
get { return iCLImageHorizontalResolution; }
set { iCLImageHorizontalResolution = value; }
}
private short? iCLImageVerticalResolution;
public short? ICLImageVerticalResolution
{
get { return iCLImageVerticalResolution; }
set { iCLImageVerticalResolution = value; }
}
private byte? iCLImageColorDepth;
public byte? ICLImageColorDepth
{
get { return iCLImageColorDepth; }
set { iCLImageColorDepth = value; }
}
private int iCLImageBytes;
public int ICLImageBytes
{
get { return iCLImageBytes; }
set { iCLImageBytes = value; }
}
private byte[] iCLImageMD5Hash;
public byte[] ICLImageMD5Hash
{
get { return iCLImageMD5Hash; }
set { iCLImageMD5Hash = value; }
}
private string preparedFilePath;
public string PreparedFilePath
{
get { return preparedFilePath; }
set { preparedFilePath = value; }
}
private string displayImageFullPath;
public string DisplayImageFullPath
{
get { return displayImageFullPath; }
set { displayImageFullPath = value; }
}
/// <summary>
/// The results of full page OCR for this image, if available. This field may
/// not always be populated depending on the service method invoked and/or configuration
/// of document OCR for the particular site.
/// </summary>
public string DocumentOcr
{
get { return documentOcr; }
set { documentOcr = value; }
}
private OcrDataRecord _ocrrecord;
/// <summary>
/// Fully parsed ocr data.
/// </summary>
public OcrDataRecord OcrRecord
{
get { return _ocrrecord; }
set { _ocrrecord = value; }
}
private string _workItemLogNote;
public string WorkItemLogNote
{
get { return _workItemLogNote; }
set { _workItemLogNote = value; }
}
private bool _isDeleted;
public bool IsDeleted
{
get { return _isDeleted; }
set { _isDeleted = value; }
}
public override string ToString()
{
return string.Format("WIDate: {0} ,WISequence: {1}, WIDetailSequence: {2}, WIDetailType: {3}",
WorkItemDate.ToShortDateString(), WISequence, WIDetailSequence, WorkItemDetailType);
}
private DateTime? _batchStartDate;
public DateTime? BatchStartDate
{
get { return _batchStartDate; }
set { _batchStartDate = value; }
}
private short? _batchSeqNum;
public short? BatchSeqNum
{
get { return _batchSeqNum; }
set { _batchSeqNum = value; }
}
private short? _envelopeSequence;
public short? EnvelopeSequence
{
get { return _envelopeSequence; }
set { _envelopeSequence = value; }
}
}
other code to return
public async Task<WorkItemDetail> GetWorkItemDetailAsync(int userNumber, int userNumberExternal, string applicationId, short computerNumber, DateTime wiDate, int wiSequence, int wiDetailSequence, bool includeImage)
{
using (HttpClient client = base.CreateHttpClient())
{
WorkItemDetail workitemdetail = new WorkItemDetail();
var service_result = await client.GetAsync(string.Format("api/work-item-detail?userNumber={0}&userNumberExternal={1}&applicationId={2}&computerNumber={3}&wiDate={4}&wiSequence={5}&wiDetailSequence={6}&includeImage={7}", userNumber, userNumberExternal, applicationId, computerNumber, wiDate, wiSequence, wiDetailSequence, includeImage));
await ValidateResponseAsync(service_result);
workitemdetail = await service_result.Content.ReadAsAsync<WorkItemDetail>();
return workitemdetail;
}
}

.Net BinaryFormater System.ArgumentNullException: Object Graph cannot be null. Parameter name: graph

I'm attempting to serialize a System.Collections.Generic.List of objects but am running into an error I can't figure out.
The objects I am trying to serialize are pretty vanilla, just a lot of strings and integers properties.
I'm using the following code to serialize a list of objects.
private static Boolean WriteItemDataList(List<ItemData> itemDataList)
{
try
{
using (Stream stream = File.Open(#"H:\1.cache", FileMode.Create))
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(stream, itemDataList);
}
}
catch (Exception exception)
{
Trace.WriteLine(exception.ToString());
return false;
}
return true;
}
I am getting this error.
A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
System.ArgumentNullException: Object Graph cannot be null.
Parameter name: graph
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
at A.B.C.Program.WriteItemDataList(List`1 itemDataList) in z:\dev\Projects\\\Program.cs:line 46
This is the object in the list I'm trying to serialize
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace A.B.ClassLibrary
{
[Serializable()]
public class ItemData
{
//FIELDS
protected String abcCode;
protected Decimal averageCost;
protected String basicUnitOfMeasure;
protected Int32 basicUnitOfMeasureOrderQuantity;
protected String businessArea;
protected String businessAreaDescription;
protected String buyer;
protected Decimal concraftsPrice;
protected String description;
protected String domesticImport;
protected Decimal dpPrice;
protected String itemGroup;
protected String itemGroupDescription;
protected String itemNumber;
protected String itemType;
protected String itemTypeDescription;
protected String name;
protected String nameOfUserResponsible;
protected Decimal netPrice;
protected Int32 onOrderQuantity;
protected String planner;
protected String prePrice;
protected Decimal prizmPrice;
protected String procurementGroup;
protected String procurementGroupDescription;
protected String procureMethod;
protected String productGroup;
protected String productGroupDescription;
protected Int32 purchaseMinimumQuantity;
protected Int32 purchaseMultipleQuantity;
protected String purchaseUnitOfMeasure;
protected Decimal quantityBreakPrice;
protected Int32 quantityBreakQuantity;
protected Int32 reservedQuantity;
protected String responsible;
protected Decimal retailPrice;
protected String royalty;
protected String salesPriceUnitOfMeasure;
protected String seasonality;
protected Int32 sellMinimumQuantity;
protected String sellUnitOfMeasure;
protected String status;
protected String supplierItemNumber;
protected String supplierName;
protected String supplierNumber;
protected String topCust;
protected Int32 totalLeadTime;
protected String upc;
protected Int32 warehouseOnHandQuantity;
//PROPERTIES
public virtual String AbcCode
{
get { return abcCode; }
set { abcCode = value; }
}
public virtual Decimal AverageCost
{
get { return averageCost; }
set { averageCost = value; }
}
public virtual String BasicUnitOfMeasure
{
get { return basicUnitOfMeasure; }
set { basicUnitOfMeasure = value; }
}
public virtual Int32 BasicUnitOfMeasureOrderQuantity
{
get { return basicUnitOfMeasureOrderQuantity; }
set { basicUnitOfMeasureOrderQuantity = value; }
}
public virtual String Buyer
{
get { return buyer; }
set { buyer = value; }
}
public virtual String BusinessArea
{
get { return businessArea; }
set { businessArea = value; }
}
public virtual String BusinessAreaDescription
{
get { return businessAreaDescription; }
set { businessAreaDescription = value; }
}
public virtual Decimal ConcraftsPrice
{
get { return concraftsPrice; }
set { concraftsPrice = value; }
}
public virtual String Description
{
get { return description; }
set { description = value; }
}
public virtual String DomesticImport
{
get { return domesticImport; }
set { domesticImport = value; }
}
public virtual Decimal DpPrice
{
get { return dpPrice; }
set { dpPrice = value; }
}
public virtual String ItemGroup
{
get { return itemGroup; }
set { itemGroup = value; }
}
public virtual String ItemGroupDescription
{
get { return itemGroupDescription; }
set { itemGroupDescription = value; }
}
public virtual String ItemNumber
{
get { return itemNumber; }
set { itemNumber = value; }
}
public virtual String ItemType
{
get { return itemType; }
set { itemType = value; }
}
public virtual String ItemTypeDescription
{
get { return itemTypeDescription; }
set { itemTypeDescription = value; }
}
public virtual String Name
{
get { return name; }
set { name = value; }
}
public virtual String NameOfUserResponsible
{
get { return nameOfUserResponsible; }
set { nameOfUserResponsible = value; }
}
public virtual Decimal NetPrice
{
get { return netPrice; }
set { netPrice = value; }
}
public virtual Int32 OnOrderQuantity
{
get { return onOrderQuantity; }
set { onOrderQuantity = value; }
}
public virtual String Planner
{
get { return planner; }
set { planner = value; }
}
public virtual String PrePrice
{
get { return prePrice; }
set { prePrice = value; }
}
public virtual Decimal PrizmPrice
{
get { return prizmPrice; }
set { prizmPrice = value; }
}
public virtual String ProcurementGroup
{
get { return procurementGroup; }
set { procurementGroup = value; }
}
public virtual String ProcurementGroupDescription
{
get { return procurementGroupDescription; }
set { procurementGroupDescription = value; }
}
public virtual String ProcureMethod
{
get { return procureMethod; }
set { procureMethod = value; }
}
public virtual String ProductGroup
{
get { return productGroup; }
set { productGroup = value; }
}
public virtual String ProductGroupDescription
{
get { return productGroupDescription; }
set { productGroupDescription = value; }
}
public virtual Int32 PurchaseMinimumQuantity
{
get { return purchaseMinimumQuantity; }
set { purchaseMinimumQuantity = value; }
}
public virtual Int32 PurchaseMultipleQuantity
{
get { return purchaseMultipleQuantity; }
set { purchaseMultipleQuantity = value; }
}
public virtual String PurchaseUnitOfMeasure
{
get { return purchaseUnitOfMeasure; }
set { purchaseUnitOfMeasure = value; }
}
public virtual Decimal QuantityBreakPrice
{
get { return quantityBreakPrice; }
set { quantityBreakPrice = value; }
}
public virtual Int32 QuantityBreakQuantity
{
get { return quantityBreakQuantity; }
set { quantityBreakQuantity = value; }
}
public virtual Int32 ReservedQuantity
{
get { return reservedQuantity; }
set { reservedQuantity = value; }
}
public virtual String Responsible
{
get { return responsible; }
set { responsible = value; }
}
public virtual Decimal RetailPrice
{
get { return retailPrice; }
set { retailPrice = value; }
}
public virtual String Royalty
{
get { return royalty; }
set { royalty = value; }
}
public virtual String Seasonality
{
get { return seasonality; }
set { seasonality = value; }
}
public virtual Int32 SellMinimumQuantity
{
get { return sellMinimumQuantity; }
set { sellMinimumQuantity = value; }
}
public virtual String SellUnitOfMeasure
{
get { return sellUnitOfMeasure; }
set { sellUnitOfMeasure = value; }
}
public virtual String Status
{
get { return status; }
set { status = value; }
}
public virtual String SupplierItemNumber
{
get { return supplierItemNumber; }
set { supplierItemNumber = value; }
}
public virtual String SupplierName
{
get { return supplierName; }
set { supplierName = value; }
}
public virtual String SupplierNumber
{
get { return supplierNumber; }
set { supplierNumber = value; }
}
public virtual String TopCust
{
get { return topCust; }
set { topCust = value; }
}
public virtual Int32 TotalLeadTime
{
get { return totalLeadTime; }
set { totalLeadTime = value; }
}
public virtual String UPC
{
get { return upc; }
set { upc = value; }
}
public virtual Int32 WarehouseOnHandQuantity
{
get { return warehouseOnHandQuantity; }
set { warehouseOnHandQuantity = value; }
}
//INITIALIZE
public ItemData()
{
abcCode = null;
averageCost = 0;
basicUnitOfMeasure = null;
basicUnitOfMeasureOrderQuantity = 0;
buyer = null;
businessArea = null;
businessAreaDescription = null;
concraftsPrice = 0;
description = null;
dpPrice = 0;
domesticImport = null;
itemGroup = null;
itemGroupDescription = null;
itemNumber = null;
itemType = null;
itemTypeDescription = null;
name = null;
nameOfUserResponsible = null;
netPrice = 0;
onOrderQuantity = 0;
planner = null;
prePrice = null;
prizmPrice = 0;
procurementGroup = null;
procurementGroupDescription = null;
procureMethod = null;
productGroup = null;
productGroupDescription = null;
purchaseMinimumQuantity = 0;
purchaseMultipleQuantity = 0;
purchaseUnitOfMeasure = null;
quantityBreakPrice = 0;
quantityBreakQuantity = 0;
reservedQuantity = 0;
responsible = null;
retailPrice = 0;
royalty = null;
seasonality = null;
sellMinimumQuantity = 0;
sellUnitOfMeasure = null;
status = null;
supplierItemNumber = null;
supplierName = null;
supplierNumber = null;
topCust = null;
totalLeadTime = 0;
upc = null;
warehouseOnHandQuantity = 0;
}
}
}
The documentation for BinaryFormatter.Serialize states that it will throw an ArgumentNullException if either of the serializationStream or graph parameters are null. Since the message specifically says "Object graph cannot be null" that means that the graph parameter is null, so the itemDataList parameter to your WriteItemDataList method must be null.

InnerException:When converting a string to DateTime. parse the string to date the date before putting each variable into the DateTime object

I am trying to deserialize XML returned from an API call but am getting "InnerException:When converting a string to DateTime. parse the string to date the date before putting each variable into the DateTime object"
The XML looks like this
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<agentInventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:N1="demo.org.uk/demo/CustomsStatus" xmlns:N2="demo.org.uk/demo/UnLocation" xmlns:N3="demo.org.uk/demo/AirCarrier" xmlns="demo.org.uk/demo/AgentInventory">
<shed>ADX</shed>
<arrivalPort>
<N2:iataPortCode>LHR</N2:iataPortCode>
</arrivalPort>
<masterAirwayBillPrefix>125</masterAirwayBillPrefix>
<masterAirwayBillNumber>28121101</masterAirwayBillNumber>
<nominatedAgent>DRB</nominatedAgent>
<originPort>
<N2:iataPortCode>BOS</N2:iataPortCode>
</originPort>
<destinationPort>
<N2:iataPortCode>LHR</N2:iataPortCode>
</destinationPort>
<airCarrier>
<N3:carrierCode>BA</N3:carrierCode>
</airCarrier>
<flightNumber>235</flightNumber>
<flightDate>2012-02-09T00:00:00Z</flightDate>
<npx>10</npx>
<npr>0</npr>
<grossWeight>123.0</grossWeight>
<goodsDescription>BOOKS</goodsDescription>
<sdc>T</sdc>
<status1Set></status1Set>
<status2Set>false</status2Set>
<ccsCreationTime></ccsCreationTime>
<customsSummaryText />
<customsSummaryTime></customsSummaryTime>
<agentReference />
<isErtsPreArrival>false</isErtsPreArrival>
<isAgentPreArrival>false</isAgentPreArrival>
<isDeleted>false</isDeleted>
<finalised></finalised>
<createdOn>2012-01-24T11:50:40.86Z</createdOn>
<modifiedOn>2012-02-09T09:51:26.617Z</modifiedOn>
</agentInventory>
The code used to deserialize the XML is
if (storeXmlInventoryReturnData != null)
{
//DeSerialize XML from storeXmlInventoryReturnData variable
agentInventory myInventoryResponse = null;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(agentInventory));
myInventoryResponse = (
agentInventory)xmlSerializer.Deserialize(new StringReader(storeXmlInventoryReturnData)
);
Console.WriteLine(
#"\n\n\n INVENTORY RETURN DATA FOR AWB: {0}-{1} \n\n
Destination Port: {2} \n
Arrival Port: {3} \n
Carrier: {4} \n
Flight No: {5} \n
Flight Date: {6} \n
Customers Status: {7} \n
NPX: {8} \n
NPR {9} \n
SDC Code: {10}
\n\n Hit any key to exit...."
,
myInventoryResponse.masterAirwayBillPrefix,
myInventoryResponse.masterAirwayBillNumber,
myInventoryResponse.destinationPort,
myInventoryResponse.arrivalPort,
myInventoryResponse.airCarrier,
myInventoryResponse.flightNumber,
myInventoryResponse.flightDate,
myInventoryResponse.customsStatus,
myInventoryResponse.npx,
myInventoryResponse.npr,
myInventoryResponse.sdc,
myInventoryResponse.grossWeight,
myInventoryResponse.goodsDescription
);
Console.ReadLine();
}
else
{
Console.Write("No data returned");
}
}
The exception is thrown at;
myInventoryResponse = (
agentInventory)xmlSerializer.Deserialize(new StringReader(storeXmlInventoryReturnData));
I guess I need to convert the myInventoryResponse.flightDate to a DateTime object but I am at a loss how to achieve this?
namespace FreightSolutions {
using System;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Collections;
using System.Xml.Schema;
using System.ComponentModel;
using System.Collections.Generic;
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="asm.org.uk/Sequoia/AgentInventory")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="demo.org.uk/demo/AgentInventory", IsNullable=false)]
public partial class agentInventory {
private string shedField;
private unLocation arrivalPortField;
private string masterAirwayBillPrefixField;
private string masterAirwayBillNumberField;
private string houseAirwayBillNumberField;
private string splitReferenceNumberField;
private string nominatedAgentField;
private unLocation originPortField;
private unLocation destinationPortField;
private airCarrier airCarrierField;
private string flightNumberField;
private System.DateTime flightDateField;
private bool flightDateFieldSpecified;
private string npxField;
private string nprField;
private float grossWeightField;
private bool grossWeightFieldSpecified;
private string goodsDescriptionField;
private string sdcField;
private System.DateTime status1SetField;
private bool status1SetFieldSpecified;
private bool status2SetField;
private bool status2SetFieldSpecified;
private System.DateTime ccsCreationTimeField;
private bool ccsCreationTimeFieldSpecified;
private customsStatus customsStatusField;
private string customsSummaryTextField;
private System.DateTime customsSummaryTimeField;
private bool customsSummaryTimeFieldSpecified;
private string agentReferenceField;
private bool isErtsPreArrivalField;
private bool isErtsPreArrivalFieldSpecified;
private bool isAgentPreArrivalField;
private bool isAgentPreArrivalFieldSpecified;
private bool isDeletedField;
private bool isDeletedFieldSpecified;
private System.DateTime finalisedField;
private bool finalisedFieldSpecified;
private System.DateTime createdOnField;
private System.DateTime modifiedOnField;
private bool modifiedOnFieldSpecified;
public agentInventory() {
this.customsStatusField = new customsStatus();
this.airCarrierField = new airCarrier();
this.destinationPortField = new unLocation();
this.originPortField = new unLocation();
this.arrivalPortField = new unLocation();
}
public string shed {
get {
return this.shedField;
}
set {
this.shedField = value;
}
}
public unLocation arrivalPort {
get {
return this.arrivalPortField;
}
set {
this.arrivalPortField = value;
}
}
public string masterAirwayBillPrefix {
get {
return this.masterAirwayBillPrefixField;
}
set {
this.masterAirwayBillPrefixField = value;
}
}
public string masterAirwayBillNumber {
get {
return this.masterAirwayBillNumberField;
}
set {
this.masterAirwayBillNumberField = value;
}
}
public string houseAirwayBillNumber {
get {
return this.houseAirwayBillNumberField;
}
set {
this.houseAirwayBillNumberField = value;
}
}
public string splitReferenceNumber {
get {
return this.splitReferenceNumberField;
}
set {
this.splitReferenceNumberField = value;
}
}
public string nominatedAgent {
get {
return this.nominatedAgentField;
}
set {
this.nominatedAgentField = value;
}
}
public unLocation originPort {
get {
return this.originPortField;
}
set {
this.originPortField = value;
}
}
public unLocation destinationPort {
get {
return this.destinationPortField;
}
set {
this.destinationPortField = value;
}
}
public airCarrier airCarrier {
get {
return this.airCarrierField;
}
set {
this.airCarrierField = value;
}
}
public string flightNumber {
get {
return this.flightNumberField;
}
set {
this.flightNumberField = value;
}
}
public System.DateTime flightDate {
get {
return this.flightDateField;
}
set {
this.flightDateField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool flightDateSpecified {
get {
return this.flightDateFieldSpecified;
}
set {
this.flightDateFieldSpecified = value;
}
}
[System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
public string npx {
get {
return this.npxField;
}
set {
this.npxField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
public string npr {
get {
return this.nprField;
}
set {
this.nprField = value;
}
}
public float grossWeight {
get {
return this.grossWeightField;
}
set {
this.grossWeightField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool grossWeightSpecified {
get {
return this.grossWeightFieldSpecified;
}
set {
this.grossWeightFieldSpecified = value;
}
}
public string goodsDescription {
get {
return this.goodsDescriptionField;
}
set {
this.goodsDescriptionField = value;
}
}
public string sdc {
get {
return this.sdcField;
}
set {
this.sdcField = value;
}
}
public System.DateTime status1Set {
get {
return this.status1SetField;
}
set {
this.status1SetField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool status1SetSpecified {
get {
return this.status1SetFieldSpecified;
}
set {
this.status1SetFieldSpecified = value;
}
}
public bool status2Set {
get {
return this.status2SetField;
}
set {
this.status2SetField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool status2SetSpecified {
get {
return this.status2SetFieldSpecified;
}
set {
this.status2SetFieldSpecified = value;
}
}
public System.DateTime ccsCreationTime {
get {
return this.ccsCreationTimeField;
}
set {
this.ccsCreationTimeField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool ccsCreationTimeSpecified {
get {
return this.ccsCreationTimeFieldSpecified;
}
set {
this.ccsCreationTimeFieldSpecified = value;
}
}
public customsStatus customsStatus {
get {
return this.customsStatusField;
}
set {
this.customsStatusField = value;
}
}
public string customsSummaryText {
get {
return this.customsSummaryTextField;
}
set {
this.customsSummaryTextField = value;
}
}
public System.DateTime customsSummaryTime {
get {
return this.customsSummaryTimeField;
}
set {
this.customsSummaryTimeField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool customsSummaryTimeSpecified {
get {
return this.customsSummaryTimeFieldSpecified;
}
set {
this.customsSummaryTimeFieldSpecified = value;
}
}
public string agentReference {
get {
return this.agentReferenceField;
}
set {
this.agentReferenceField = value;
}
}
public bool isErtsPreArrival {
get {
return this.isErtsPreArrivalField;
}
set {
this.isErtsPreArrivalField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool isErtsPreArrivalSpecified {
get {
return this.isErtsPreArrivalFieldSpecified;
}
set {
this.isErtsPreArrivalFieldSpecified = value;
}
}
public bool isAgentPreArrival {
get {
return this.isAgentPreArrivalField;
}
set {
this.isAgentPreArrivalField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool isAgentPreArrivalSpecified {
get {
return this.isAgentPreArrivalFieldSpecified;
}
set {
this.isAgentPreArrivalFieldSpecified = value;
}
}
public bool isDeleted {
get {
return this.isDeletedField;
}
set {
this.isDeletedField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool isDeletedSpecified {
get {
return this.isDeletedFieldSpecified;
}
set {
this.isDeletedFieldSpecified = value;
}
}
public System.DateTime finalised {
get {
return this.finalisedField;
}
set {
this.finalisedField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool finalisedSpecified {
get {
return this.finalisedFieldSpecified;
}
set {
this.finalisedFieldSpecified = value;
}
}
public System.DateTime createdOn {
get {
return this.createdOnField;
}
set {
this.createdOnField = value;
}
}
public System.DateTime modifiedOn {
get {
return this.modifiedOnField;
}
set {
this.modifiedOnField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool modifiedOnSpecified {
get {
return this.modifiedOnFieldSpecified;
}
set {
this.modifiedOnFieldSpecified = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="demo.org.uk/demo/UnLocation")]
public partial class unLocation {
private string itemField;
private ItemChoiceType itemElementNameField;
[System.Xml.Serialization.XmlElementAttribute("iataPortCode", typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("oceanPortCode", typeof(string))]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
public string Item {
get {
return this.itemField;
}
set {
this.itemField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemChoiceType ItemElementName {
get {
return this.itemElementNameField;
}
set {
this.itemElementNameField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="demo.org.uk/demo/UnLocation", IncludeInSchema=false)]
public enum ItemChoiceType {
/// <remarks/>
iataPortCode,
/// <remarks/>
oceanPortCode,
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="demo.org.uk/demo/CustomsStatus")]
public partial class customsStatus {
private string codeField;
private string statusTextField;
public string code {
get {
return this.codeField;
}
set {
this.codeField = value;
}
}
public string statusText {
get {
return this.statusTextField;
}
set {
this.statusTextField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="demo.org.uk/demo/AirCarrier")]
public partial class airCarrier {
private string carrierCodeField;
public string carrierCode {
get {
return this.carrierCodeField;
}
set {
this.carrierCodeField = value;
}
}
}
}
For my own sanity sake, I tried getting the provided XML to work with your classes and the nullable DateTime fields.
For them to work, replace the below properties with those linked below.
The default value for a DateTime object is DateTime.MinDate, so if the incoming value is null or empty, then the property will have a value of DateTime.MinDate anyway, for this you might need to additional validation/changes if your code needs to cater for this.
#region XML Nullable helper properties
[XmlElement(ElementName = "status1Set")]
public object status1SetXml
{
get
{
// Return the main property itself here and not the field to ensure that if there are changes made to the getter,
// the resulting XML will always have the right value
return status1Set;
}
set
{
// value passed in is of type XmlNode[], so convert and get the XmlNode text, which should be the DateTime we want
// !!ASSUMPTION!! That it will alwas be XmlNode[1] type
XmlNode[] inputValue = value as XmlNode[];
if (inputValue != null)
{
DateTime.TryParse(Convert.ToString(inputValue[0].InnerText), out status1SetField);
}
}
}
[XmlElement(ElementName="ccsCreationTime")]
public object ccsCreationTimeXml
{
get
{
// Return the main property itself here and not the field to ensure that if there are changes made to the getter,
// the resulting XML will always have the right value
return ccsCreationTime;
}
set
{
// value passed in is of type XmlNode[], so convert and get the XmlNode text, which should be the DateTime we want
// !!ASSUMPTION!! That it will alwas be XmlNode[1] type
XmlNode[] inputValue = value as XmlNode[];
if (inputValue != null)
{
DateTime.TryParse(Convert.ToString(inputValue[0].InnerText), out ccsCreationTimeField);
}
}
}
[XmlElement(ElementName = "customsSummaryTime")]
public object customsSummaryTimeXml
{
get
{
// Return the main property itself here and not the field to ensure that if there are changes made to the getter,
// the resulting XML will always have the right value
return customsSummaryTime;
}
set
{
// value passed in is of type XmlNode[], so convert and get the XmlNode text, which should be the DateTime we want
// !!ASSUMPTION!! That it will alwas be XmlNode[1] type
XmlNode[] inputValue = value as XmlNode[];
if (inputValue != null)
{
DateTime.TryParse(Convert.ToString(inputValue[0].InnerText), out customsSummaryTimeField);
}
}
}
[XmlElement(ElementName = "finalised")]
public object finalisedXml
{
get
{
// Return the main property itself here and not the field to ensure that if there are changes made to the getter,
// the resulting XML will always have the right value
return finalised;
}
set
{
// value passed in is of type XmlNode[], so convert and get the XmlNode text, which should be the DateTime we want
// !!ASSUMPTION!! That it will alwas be XmlNode[1] type
XmlNode[] inputValue = value as XmlNode[];
if (inputValue != null)
{
DateTime.TryParse(Convert.ToString(inputValue[0].InnerText), out finalisedField);
}
}
}
#endregion
#region Non XML properties
[XmlIgnore]
public System.DateTime status1Set
{
get { return this.status1SetField; }
set { this.status1SetField = value; }
}
[XmlIgnore]
public System.DateTime ccsCreationTime
{
get { return this.ccsCreationTimeField; }
set { this.ccsCreationTimeField = value; }
}
[XmlIgnore]
public System.DateTime customsSummaryTime
{
get { return this.customsSummaryTimeField; }
set { this.customsSummaryTimeField = value; }
}
[XmlIgnore]
public System.DateTime finalised
{
get { return this.finalisedField; }
set { this.finalisedField = value; }
}
#endregion

'does not implement interface member 'System.ICloneable.Clone()'

I'm having a small issue calling in the Icloneable interface
I've told the class I want to use the interface as such:
class UnitClass: ICloneable
and have placed in a function for Cloning
public Object Clone()
{
return this.MemberwiseClone();
}
however for some reason the program is telling me that I have not implemented System.ICloneable.clone() I even tried giving the function the explicit name like so...
public Object System.ICloneable.Clone()
but with little effect, anybody know what I'm doing wrong?
edit: Full class
class UnitClass: ICloneable
{
//-----------------------------------------------------------------------------------------------
//----------------------------------------------Variables----------------------------------------
private int unitID; //added for xml
private string unitName;
private int unitBaseHP;
private int unitCurrentHP;
private Carrier unitCarrier;
private int unitRechargeTime;
private int turnLastPlayed;
private int strengthAgainstFighters;
private int strengthAgainstBombers;
private int strengthAgainstTurrets;
private int strengthAgainstCarriers;
//-----------------------------------------------------------------------------------------------
//---------------------------------------------Constructor---------------------------------------
public UnitClass()
{
unitID = 0;
unitName = "Name Not Set";
unitBaseHP = 0;
unitCurrentHP = 0;
unitCarrier = null;//Carrier works as faction ie red/blue or left/right
unitRechargeTime = 0;
turnLastPlayed = 0;
strengthAgainstFighters = 0;
strengthAgainstBombers = 0;
strengthAgainstTurrets = 0;
strengthAgainstCarriers = 0;
}
//-----------------------------------------------------------------------------------------------
//---------------------------------------------Gets and Sets-------------------------------------
public int UnitID//public
{
set { unitID = value; }
get { return unitID; }
}
public string UnitName//public
{
set { unitName = value; }
get { return unitName; }
}
public int UnitBaseHP//public
{
set { unitBaseHP = value; }
get { return unitBaseHP; }
}
public int UnitCurrentHP//public
{
set { unitCurrentHP = value; }
get { return unitCurrentHP; }
}
public Carrier UnitCarrier//public
{
set { unitCarrier = value; }
get { return unitCarrier; }
}
public int UnitRechargeTime//public
{
set { unitRechargeTime = value; }
get { return unitRechargeTime; }
}
public int TurnLastPlayed//public
{
set { turnLastPlayed = value; }
get { return turnLastPlayed; }
}
public int StrengthAgainstFighters//public
{
set { strengthAgainstFighters = value; }
get { return strengthAgainstFighters; }
}
public int StrengthAgainstBombers//public
{
set { strengthAgainstBombers = value; }
get { return strengthAgainstBombers; }
}
public int StrengthAgainstTurrets//public
{
set { strengthAgainstTurrets = value; }
get { return strengthAgainstTurrets; }
}
public int StrengthAgainstCarriers//public
{
set { strengthAgainstCarriers = value; }
get { return strengthAgainstCarriers; }
}
//---------------------------------------------------------------------------
public object Clone()
{
return this.MemberwiseClone();
}
}
This built fine for me.
public class MyClone : ICloneable
{
public object Clone()
{
return this.MemberwiseClone();
}
}
You don't perhaps want to share any more of your class? Nothing is really jumping out at me.

Categories

Resources