C# System.Windows.ni.dll Windows phone 8中发生“System.Reflection.TargetInvocationException”类型的异常

C# System.Windows.ni.dll Windows phone 8中发生“System.Reflection.TargetInvocationException”类型的异常,c#,windows-phone-8,C#,Windows Phone 8,我正在开发一个笔记应用程序。在备忘编辑页面上,当用户创建新备忘并键入文本,然后按下手机的后退按钮时,代码将创建新备忘,我尝试用新行替换回车。当我在应用程序中尝试此操作时,会出现此异常。System.Windows.ni.dll中发生类型为“System.Reflection.TargetInvocationException”的未处理异常,并打开一个新的文件选项卡,显示System.Windows.pdb not loaded 这就是代码被破坏的地方 protected async overri

我正在开发一个笔记应用程序。在备忘编辑页面上,当用户创建新备忘并键入文本,然后按下手机的后退按钮时,代码将创建新备忘,我尝试用新行替换回车。当我在应用程序中尝试此操作时,会出现此异常。System.Windows.ni.dll中发生类型为“System.Reflection.TargetInvocationException”的未处理异常,并打开一个新的文件选项卡,显示System.Windows.pdb not loaded 这就是代码被破坏的地方

protected async override void OnNavigatedFrom(NavigationEventArgs e)
    {
        base.OnNavigatedFrom(e);

        // we are suppose to save the note, when user navigates away from the page
        ourNote.Note = editorTextBox.Text.Replace("\r", "\n");
        await App.ViewModel.UpdateNotes();
    }
有人知道我做错了什么吗? 这是NoteModel类,ourNote变量属于这种类型

public class NoteModel : INotifyPropertyChanged
{

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    private string _id;

    public string ID 
    {
        get 
        { 
            return _id;
        }
        set 
        {
            // check to see if the value isn't the same with _id if not raise a propertychanged event via the method
            if (value != _id)
            {
                _id = value;
                NotifyPropertyChanged("ID");
            }
        } 
    }

    private string _modDate;

    public string ModifiedDate
    {
        get
        {
            return _modDate;
        }
        set
        {
            // check to see if the value isn't the same with _id if not raise a propertychanged event via the method
            if (value != _modDate)
            {
                _modDate = value;
                NotifyPropertyChanged("ModifiedDate");
            }
        }
    }

    private string _note;

    public string Note
    {
        get
        {
            return _note;
        }
        set
        {
            // check to see if the value isn't the same with _id if not raise a propertychanged event via the method
            if (value != _note)
            {
                _note = value;

                string[] lines = _note.Split('\n'); // we change this from '\r' to '\n' because of winRT serializaiton and deserialization ends up with line feeds only, removes carriage returns
                if (lines.Length > 0)
                {
                    FirstLine = lines[0]; // we removed .Replace("\n", ""); since no more carriage returns
                }
                else
                {
                    // what if there is no first line
                    FirstLine = "(empty)";
                }
                NotifyPropertyChanged("Note");
            }
        }
    }

    private string _firstLine;

    public string FirstLine
    {
        get
        {
            return _firstLine;
        }
        set
        {
            // check to see if the value isn't the same with _id if not raise a propertychanged event via the method
            if (value != _firstLine)
            {
                _firstLine = value;
                NotifyPropertyChanged("FirstLine");
            }
        }
    }
}

我认为发生异常是因为您返回页面时,笔记列表页面的某些元素未加载


App.ViewModel.UpdateNotes是否更新笔记列表页面的元素?如果是,您应该只更新数据,然后在导航到页面时更新notes列表页面元素。

您能再看一次吗,我刚刚做了一些编辑代码是否引发NullReferenceException和TargetInvocationException?或者仅TargetInvocationException?当我将异常消息打印到调试器时,在LoverworldNote.DLL对象引用中发生了类型为“System.NullReferenceException”的第一次意外异常,该对象引用未设置为对象的实例,因此我得到了您没有查看异常的两个异常。对其调用ToString并将结果粘贴到。TIE是在类型的构造函数中引发的异常。异常可能位于InnerException属性中。