C# Azure MobileService空引用异常

C# Azure MobileService空引用异常,c#,azure,windows-phone-8.1,azure-mobile-services,C#,Azure,Windows Phone 8.1,Azure Mobile Services,我目前正在用Azure为windows phone 8.1开发一个应用程序。(根据我的经验,我不会向你推荐这个)。无论如何我在其中有多个控制器类,它们确实做了同样的事情(检查我的数据库中是否已经存在某些东西,如果不存在,它就会创建它)。我遇到的问题是Read()函数,该函数检查数据库中是否存在条目: public async void Read(Device device) { IMobileServiceTable mobileServiceTable = Connect();

我目前正在用Azure为windows phone 8.1开发一个应用程序。(根据我的经验,我不会向你推荐这个)。无论如何我在其中有多个控制器类,它们确实做了同样的事情(检查我的数据库中是否已经存在某些东西,如果不存在,它就会创建它)。我遇到的问题是Read()函数,该函数检查数据库中是否存在条目:

public async void Read(Device device)
{
    IMobileServiceTable mobileServiceTable = Connect();
    MobileServiceCollection<Device, Device> devices = null;
    try
    {
        devices = await mobileServiceTable.MobileServiceClient.GetTable<Device>().Where(d => d.Manufacturer == device.Manufacturer && d.Model == device.Model).ToCollectionAsync();
    }
    catch (Exception e)
    {
        if (_onDeviceControllerListener != null)
        {
            _onDeviceControllerListener.OnError(ControllerError.Error.ReadFromDatabase, e.ToString());
        }
            return;
        }

    if (_onDeviceControllerListener != null && devices != null)
    {
        _onDeviceControllerListener.OnRead(devices);
    }
}
公共异步无效读取(设备)
{
IMobileServiceTable mobileServiceTable=Connect();
MobileServiceCollection设备=空;
尝试
{
devices=Wait mobileServiceTable.MobileServiceClient.GetTable()。其中(d=>d.Manufacturer==device.Manufacturer&&d.Model==device.Model)。ToCollectionAsync();
}
捕获(例外e)
{
if(_onDeviceControllerListener!=null)
{
_onDeviceControllerListener.OnError(ControllerError.Error.ReadFromDatabase,例如ToString());
}
返回;
}
if(_onDeviceControllerListener!=null&&devices!=null)
{
_onDeviceControllerListener.OnRead(设备);
}
}
这一个可以很好地工作,但基本上只是一个副本的oder会抛出一个NullReferenceException,行为“apps=wait-mobileServiceTab…”:

公共异步无效读取(Model.App)
{
IMobileServiceTable mobileServiceTable=Connect();
MobileServiceCollection应用程序=null;
试一试{
apps=wait mobileseservicetable.mobileseserviceclient.GetTable()。其中(a=>a.HardwareId==app.HardwareId&&a.PackageId==app.PackageId)。ToCollectionAsync();
}
捕获(例外e)
{
if(_onAppControllerListener!=null)
{
_onAppControllerListener.OnError(ControllerError.Error.ReadFromDatabase,例如ToString());
}
返回;
}
if(_onAppControllerListener!=null)
{
_onAppControllerListener.OnRead(应用程序);
}
}
有人知道问题出在哪里吗?
感谢您的帮助

您可以添加一个try…catch块并检查“MobileServiceInvalidOperationException”异常。还可以查看调用堆栈以了解发生了什么

如果您成功呼叫移动服务以检索数据,fiddler跟踪也会让您知道。然后,您可以确定问题是否在于如何处理代码中的数据

再看一看你的MobileServiceContext类,确保所有属性都被考虑在内,尤其是使用“Model.App”类的属性。例如

public virtual DbSet<Model.App> SomeProperty { get; set; }
公共虚拟数据库集SomeProperty{get;set;}

希望这有帮助

您的异常的堆栈跟踪是什么?您能否单步执行它,并在抛出错误时告诉我们哪个对象为null?
public virtual DbSet<Model.App> SomeProperty { get; set; }