根级别的XML数据无效

时间:2018-09-23 01:12:36

标签: c# .net

我有以下代码来获取用户的个人资料并将其返回到页面,我一直遇到的问题是我偶尔在根级别获取XML错误数据是无效的。有什么办法可以抓到这个吗?

public static Profile GetProfile(string username)
{
    // We cache the profile for 1 minute so we can speed up access, but still return fairly fresh profiles

    // lock for thread safety
     Profile profile = null;
     lock (s_profileCache)
    {
        if (!s_profileCache.TryGetValue(username, out profile)
            || profile.CreateTime < DateTime.UtcNow.AddMinutes(-1))
        {
            // missing or stale, fetch it
            profile = RetrieveProfile(username);

            // save it in the cache

            s_profileCache[username] = profile;

            // Store purchases in purchase cache, if not already present (puchases don't change
            // so probably no point overwriting them?)
            foreach (var p in profile.Purchases)
            {
                Purchase purchase = null;
                s_purchaseCache[p.Id] = purchase;
            }
        }
    }

0 个答案:

没有答案
相关问题