2012-06-12 3 views
0

일련 화를 사용하여 IsolatedStorageFile에 저장 한 XML 파일을 읽으려고합니다. try 블록에서 XML 파일을 다시 읽으려고하면 Deserialization 단계에서 예외가 발생합니다. 내가 뭔가 잘못하고 있는거야? 이 문제를 어떻게 해결할 수 있습니까?Windows Phone 7 예외 직렬화 해제

베팅 등급 :

public class Bet 
{ 
    public String Amount { get; set; } 
    public String Opponent { get; set; } 
    public String Terms { get; set; } 
    public int Result { get; set; } 
    public String ResultColor { get; set; } 

    public Bet(String amount, String opponent, String terms, int result, String rcolor) 
    { 
     this.Amount = amount; 
     this.Opponent = opponent; 
     this.Terms = terms; 
     this.Result = result; 
     this.ResultColor = rcolor; 
    } 
} 

저장 /로드 베팅 기능

public void SaveBets() 
{ 
    List<Bet> bets = new List<Bet>(); 

    foreach (Bet item in openBetList) 
     bets.Add(item); 

    foreach (Bet item in closedBetList) 
     bets.Add(item); 

    // Write to the Isolated Storage 
    XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); 
    xmlWriterSettings.Indent = true; 

    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
    { 
     using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Bets.xml", FileMode.Create)) 
     { 
      XmlSerializer serializer = new XmlSerializer(typeof(List<Bet>)); 
      using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings)) 
      { 
       serializer.Serialize(xmlWriter, bets); 
      } 
     } 
    } 
} 

public void LoadBets() 
{ 
    try 
    { 
     using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Bets.xml", FileMode.Open)) 
      { 
       XmlSerializer serializer = new XmlSerializer(typeof(List<Bet>)); 
       List<Bet> data = (List<Bet>)serializer.Deserialize(stream); 

       if(data.Count > 0) 
        foreach (Bet item in data) 
        { 
         if (item.Result == 0) 
          openBetList.Add(item); 
         else 
          closedBetList.Add(item); 
        } 
      } 
     } 
    } 
    catch 
    { 
     //add some code here 
    } 
} 

감사합니다!

+1

"는"예외? 무슨 예외? –

답변

1

예외는 무엇입니까?

난 당신이 매개 변수가없는 생성자가 필요 remeber 수 있듯이 ...

+0

+1 Youre right, 제 생각 엔 여기에 문제가 있다고 생각합니다 –

+0

예외를 볼 수 있도록 catch에 "(Exception ex)"을 추가하십시오 –

+0

감사합니다 !! :) 생성자가없는 생성자가 트릭을 만들었습니다! – krisharmas