新浪微博Win8 APP启动秒退Bug的分析

自从更新Win8 RTM后,应用程序商店里面的新浪客户端就不能正常运行,多次卸载重装都不行,于是祭出ILSpy把那个APP反编译了。

经过多次调试发现是以下这段代码报错

private async void GetDeviceInfo()
{
    string[] array = new string[]
    {
        "System.Devices.ModelName",
        "System.Devices.Manufacturer"
    };
    string text = "System.Devices.LocalMachine:=System.StructuredQueryType.Boolean#True";
    PnpObjectCollection pnpObjectCollection = await PnpObject.FindAllAsync(PnpObjectType.DeviceContainer, array, text);
    if (pnpObjectCollection != null && ((IReadOnlyCollection<PnpObject>)pnpObjectCollection).Count > 0)
    {
        PnpObject pnpObject = ((IReadOnlyList<PnpObject>)pnpObjectCollection)[0];
        WeiboConstant.DeviceModel = pnpObject.get_Properties()[array[0]].ToString();
        WeiboConstant.DeviceManufacturer = pnpObject.get_Properties()[array[1]].ToString();
    }
    PackageVersion version = Package.Current.Id.Version;
    WeiboConstant.UAValue = string.Format("{0}__weibo__{1}.{2}.{3}__win8pad", new object[]
    {
        WeiboConstant.DeviceModel,
        version.Major,
        version.Minor,
        version.Build
    });
}

报错的地方为:

WeiboConstant.DeviceModel = pnpObject.get_Properties()[array[0]].ToString();
WeiboConstant.DeviceManufacturer = pnpObject.get_Properties()[array[1]].ToString();

这两句抛出了没有处理的null异常

原因很简单,由于笔者用得不是品牌电脑,所以没有制造商信息,故属性值为null,然后代码把null值ToString()的时候就会抛出null异常

这个在微软官方论坛上得到了证实(http://social.msdn.microsoft.com/Forums/zh-CN/metroappzhcn/thread/c7397740-4b30-4324-bf95-3c2bf84fc60d

笔者和新浪微博Win8 APP的其中一位开发人员取得了联系,反馈了这个Bug并拿到了修正Bug后的离线包,已经正常用上了眨眼

离线包安装需要最少开发者越狱,和一定的系统知识这里我就先不发了,各位看官还是等应用市场更新吧

另:目测 WeiboConstant.DeviceModel 应该就是日后Win8品牌机尾巴识别用的了,先在这备注一下,日后修改尾巴的时候可以用到吐舌鬼脸