I have a C# application in .Net 4.0. I have a custom object that is called OrderBlock. This custom object contains a few properties and a list that contains another custom object called Order. When the application runs it saves the OrderBlock object to my settings file.
I can see in the settings file the OrderBlock has correctly saved the properties & list of orders. The issue I have though is next time I go to run the application and try to read the OrderBlock object is doesn't work. It just returns null.
_orderBlockEntity = Properties.Settings.Default.MyOrderBlock;
Other settings I can read fine by using the a line similar to the line above. However the OrderBlock object is the only custom type I am using in the settings file.
The OrderBlock & Order objects contain properties with XmlElement attributes that rename the property to another name, this is for when sending an xml message - have no idea if this is an issue?
[XmlElement("tF_Transactions")]
public List<Order> Orders
{
get { return _orders; }
set { _orders = value; OnPropertyChanged("Orders"); }
}
**** EDIT ******
Below is where I save my object to the settings file - which does work.
Properties.Settings.Default.MyOrderBlock = _orderBlock;
Properties.Settings.Default.Save();
The code in the Designer is as below.
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public global::FC.OMS.TF.Entities.OrderBlock MyOrderBlock {
get {
return ((global::FC.OMS.TF.Entities.OrderBlock)(this["MyOrderBlock"]));
}
set {
this["MyOrderBlock"] = value;
}
}
Below is a snipet of my settings file - the rest is just more orders. The other settings shown below work fine in that after restarting my application their values can be read. The scope for all the settings below is User.
<setting name="LastFileDateTime" serializeAs="String">
<value>11/22/2013 09:01:29</value>
</setting>
<setting name="MessageSent" serializeAs="String">
<value>True</value>
</setting>
<setting name="MessageRecieved" serializeAs="String">
<value>True</value>
</setting>
<setting name="MyOrderBlock" serializeAs="Xml">
<value>
<SystemSettings>
<sCode>Key</sCode>
<sValue>msawyer131122090129848</sValue>
</SystemSettings>
<tF_Transactions>
<iId>17</iId>
<sSecurityId>GB0.144</sSecurityId>
<sPortfolio>OEE285</sPortfolio>
<sBuySell>B</sBuySell>
<sBuyCurrency>GBP</sBuyCurrency>
<sCostCurrency>GBP</sCostCurrency>
<iTransactionType>0</iTransactionType>
<dfBuyAmount>32000</dfBuyAmount>
<dfCostAmount xsi:nil="true" />
<dtDealDate>2013-11-22T09:01:29.8406559Z</dtDealDate>
<dtStartDate xsi:nil="true" />
<dtEndDate xsi:nil="true" />
<sUser>msawyer</sUser>
<sReason>FICLIENT</sReason>
<iStatus>0</iStatus>
<sComments>Bulk upload by msawyer at 22/11/2013 09:01:29</sComments>
<bGenerateDescription>true</bGenerateDescription>
<sDealer>msawyer</sDealer>
</tF_Transactions>
<tF_Transactions>
<iId>16</iId>
<sSecurityId>GB1.232</sSecurityId>
<sPortfolio>OEE285</sPortfolio>
<sBuySell>B</sBuySell>
<sBuyCurrency>GBP</sBuyCurrency>
<sCostCurrency>GBP</sCostCurrency>
<iTransactionType>0</iTransactionType>
<dfBuyAmount>30000</dfBuyAmount>
<dfCostAmount xsi:nil="true" />
<dtDealDate>2013-11-22T09:01:29.8396794Z</dtDealDate>
<dtStartDate xsi:nil="true" />
<dtEndDate xsi:nil="true" />
<sUser>msawyer</sUser>
<sReason>FICLIENT</sReason>
<iStatus>0</iStatus>
<sComments>Bulk upload by msawyer at 22/11/2013 09:01:29</sComments>
<bGenerateDescription>true</bGenerateDescription>
<sDealer>msawyer</sDealer>
</tF_Transactions>