2012-06-19 22 views
0

我跟随this tutorial,我被卡在TwitterAcces类(包含twitter标记)被序列化的部分。这是序列化方法被称为:WIndows电话上的数据序列化

void CallBackVerifiedResponse(OAuthAccessToken at, TwitterResponse response) 
    { 
     if (at != null) 
     { 
      SerializeHelper.SaveSetting<TwitterAccess>("TwitterAccess", new TwitterAccess 
      { 
       AccessToken = at.Token, 
       AccessTokenSecret = at.TokenSecret, 
       ScreenName = at.ScreenName, 
       UserId = at.UserId.ToString() 
      }); 
     } 
    } 

这是我SerializeHelper.cs:

public class SerializeHelper 
{ 
    public static void SaveSetting<T>(string fileName, T dataToSave) 
    { 
     using (var store = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      try 
      { 
       using (var stream = store.CreateFile(fileName)) 
       { 
        var serializer = new DataContractSerializer(typeof(T)); 
        serializer.WriteObject(stream, dataToSave); 
       } 
      } 
      catch (Exception e) 
      { 
       MessageBox.Show(e.Message); 
       return; 
      } 
     } 
    } 

} 

我得到的错误是:The type or namespace name 'DataContractSerializer' could not be found (are you missing a using directive or an assembly reference?)的Visual Studio不能帮我解决问题。它建议创建一个新班级。我搜索了一下,我认为这个班级应该在我正在使用的System.Runtime.Serialization;之内,但这并不能解决问题。

+0

你在项目中引用了'System.Runtime.Serialization.dll'吗? – MarcinJuraszek

+0

我有'使用System.Runtime.Serialization;'语句。还是应该以其他方式将其添加到项目中? – networkprofile

+0

http://msdn.microsoft.com/en-us/library/wkze6zky(v=vs.80).aspx - 检查'在Visual C#或Visual J#中添加引用'部分 – MarcinJuraszek

回答

4

您必须添加System.Runtime.Serialization.dll在您的项目中引用。