PurpleSprinkles
PurpleSprinkles

Reputation: 41

Why does the error, "An exception was thrown by the target on an invocation" appear when running MessagingCenter.Send?

When the project runs MessagingCenter.Send, it throws the error, "An exception has been thrown by the target of an invocation."

This error appeared the first time I deployed my project after restarting Visual Studio, and I had not changed the code inside of the MessagingCenter.Subscribe method since the last deployment.

How do I view what this exception is? Edit: I couldn't copy the call stack normally, so here's a screenshot

Upvotes: 0

Views: 1227

Answers (1)

PurpleSprinkles
PurpleSprinkles

Reputation: 41

By commenting out some code, I figured out what the problem was.

The true error was that I was trying to edit the index of a list that was out of range. The list gets its items from a file in Internal Storage, so that file was either corrupted or reset somehow, and the list was reset with it.

It's an easy fix, and had I known that MessagingCenter.Subscribe will trace back an exception to MessagingCenter.Send, I wouldn't have asked this question.

Upvotes: 1

Related Questions