【问题标题】:Data serialization on WIndows PhoneWindows Phone 上的数据序列化
【发布时间】:2012-06-19 16:52:01
【问题描述】:

我正在关注this tutorial,但我被困在 TwitterAcces 类(包含 twitter 令牌)被序列化的部分。这是调用序列化方法的地方:

    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; 内,但这并不能解决问题。

【问题讨论】:

  • 您的项目中是否引用了System.Runtime.Serialization.dll
  • 我有using System.Runtime.Serialization; 声明。还是应该以其他方式将其添加到项目中?
  • msdn.microsoft.com/en-us/library/wkze6zky(v=vs.80).aspx - 选中“在 Visual C# 或 Visual J# 中添加引用”部分
  • 添加它作为参考修复了我的错误,谢谢!将此作为答案提交,我会接受。

标签: windows-phone-7 twitter datacontractserializer


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    相关资源
    最近更新 更多