简体   繁体   中英

An exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll windows phone 8

I am building a note taking app. on the note editing page, when users create new note and types in text, and then press the phone's back button, the code is suppose to create a new note and i try to replace carriage returns with new line. when i try this in the app i get this exception.An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll and a new file tab opens saying System.Windows.pdb not loaded This is the code where it breaks

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();
    }

does anyone know what i'm getting wrong? this is the NoteModel class, the ourNote variable is of this type.

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");
            }
        }
    }
}

I think the exception occurred because some elements of your notes list page (the page when you back) aren't loaded.

Does App.ViewModel.UpdateNotes() update a element of your notes list page? If yes, you should only update data, and then update notes list page element when you OnNavigateTo the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM