Laxman
Laxman
CC#
Created by Laxman on 5/21/2023 in #help
✅ .NET MAUI System.Reflection.TargetInvocationException
Good evening, I hope you are doing well. I have the following problem, I would like to decrypt a string with Newtonsoft, however, when I try this in the Constructor my app crashes (error) but when I try it in a RelayCommand it works but the CollectionView doesn't update. The Code:
public SelectedOverviewViewModel()
{
CharactersList.Add(new CharacterModel
{
Name="Hi"
});

List<CharacterModel> characters = new List<CharacterModel>();
characters = JsonConvert.DeserializeObject<List<CharacterModel>>(JSONstring); // Crashes here

foreach (CharacterModel character in characters)
{
CharactersList.Add(character);
}
}

[RelayCommand]
void Load()
{
List<CharacterModel> characters = new List<CharacterModel>();
characters = JsonConvert.DeserializeObject<List<CharacterModel>>(JSONstring);

foreach (CharacterModel character in characters)
{
CharactersList.Add(character);
}
}
public SelectedOverviewViewModel()
{
CharactersList.Add(new CharacterModel
{
Name="Hi"
});

List<CharacterModel> characters = new List<CharacterModel>();
characters = JsonConvert.DeserializeObject<List<CharacterModel>>(JSONstring); // Crashes here

foreach (CharacterModel character in characters)
{
CharactersList.Add(character);
}
}

[RelayCommand]
void Load()
{
List<CharacterModel> characters = new List<CharacterModel>();
characters = JsonConvert.DeserializeObject<List<CharacterModel>>(JSONstring);

foreach (CharacterModel character in characters)
{
CharactersList.Add(character);
}
}
I´m using: CommunityToolkit.MAUI (latest) CommunityToolkit.MVVM (latest) Newton.Json (latest)
18 replies