'Unable to find a constructor to use for type crash Xamarin iOS when submitting AppStore
I have a problem that I don't quite understand. It's still when I submit the App to the AppStore. Apple responds with an error like this:
SIGABRT: Unable to find a constructor to use for type XXX.Models.ProductCategory. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path '[0].ID', line 1, position 7.
I checked my Model: ProductCategory.cs
public class ProductCategory
{
public int ID { get; set; }
public string CodeRandom { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Code { get; set; }
public int Parent_ID { get; set; }
public bool Status { get; set; }
public DateTime CreateDay { get; set; }
public string Banner { get; set; }
public List<ProductCategoryChild> ProductCategoryChilds { get; set; }
}
DashboardViewModel.cs
public ObservableCollection<ProductCategory> Category { get; }
public ObservableCollection<ProductCategory> CategoryBannerIndex { get; }
async Task ExecuteLoadDashboardCommand()
{
IsBusy = true;
try
{
CategoryBannerIndex.Clear();
var categoryChoosList = await _apiService.LoadCategoryChoose();
foreach (var cate in categoryChoosList)
{
CategoryBannerIndex.Add(cate);
}
Category.Clear();
var cateGetList = await _apiService.LoadCate();
foreach (var cate in cateGetList)
{
Category.Add(cate);
}
}
catch (Exception)
{
throw;
}
finally
{
IsBusy = false;
}
}
I test on emulator and real device. Everything runs fine. However, Apple responded to the crash. Is in the loop I declared var cate in... to be the same so it shouldn't be an exception? Here is the full response from Apple I got from AppCenter:
Looking forward to everyone's help. Thank you
Update
public class ProductCategory
{
public ProductCategory()
{
}
public int ID { get; set; }
public string CodeRandom { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Code { get; set; }
public int Parent_ID { get; set; }
public bool Status { get; set; }
public DateTime CreateDay { get; set; }
public string Banner { get; set; }
public List<ProductCategoryChild> ProductCategoryChilds { get; set; }
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


