iOS端打开页面触发System.MissingFieldException异常,Android正常求解答
Hey there! Sorry to hear you're hitting this annoying issue on iOS while Android works perfectly—let's break down what's likely going on and how to fix it.
First off, that System.MissingFieldException for Xamarin.Forms.BindableProperty almost always ties to environment or dependency mismatches between your iOS and other projects, rather than the specific code snippet you shared (that OnAppearing logic looks totally fine at a glance). Here are the most common fixes to try:
1. Ensure Xamarin.Forms versions match across all projects
This is the #1 culprit for cross-platform Xamarin issues. Sometimes NuGet packages get out of sync between your shared project, Android project, and iOS project.
- Right-click your solution → Manage NuGet Packages for Solution
- Check the
Installedtab for Xamarin.Forms. Make sure every single project (shared, Android, iOS) has the exact same version installed. If not, upgrade/downgrade to align them all to a stable release.
2. Clean up build artifacts and rebuild
Stale build cache on iOS can cause weird missing field errors even when your code is correct. Follow these steps:
- Right-click the solution → Clean Solution
- Manually delete the
binandobjfolders from your iOS project (and shared project, just to be safe) - Restart your IDE (Visual Studio or VS for Mac)
- Rebuild the solution and run the iOS project again
3. Verify your BindableProperty definition
Double-check that the BindableProperty related to CompetitionId (or any other properties in GnsportsGameEventListPage1ModelData) is correctly defined:
- Make sure it's declared as
public static readonly(this is non-negotiable for BindableProperties) - Avoid any conditional compilation directives (like
#if !IOS) that might exclude the property from the iOS build - Example of a correct BindableProperty definition:
public static readonly BindableProperty CompetitionIdProperty = BindableProperty.Create(nameof(CompetitionId), typeof(int), typeof(GnsportsGameEventListPage1ModelData), default(int)); public int CompetitionId { get => (int)GetValue(CompetitionIdProperty); set => SetValue(CompetitionIdProperty, value); }
4. Reinstall Xamarin.Forms NuGet packages
If the above steps don't work, corrupted NuGet packages might be the issue:
- Uninstall Xamarin.Forms from all projects in the solution
- Clean the solution and delete
bin/objfolders again - Reinstall the same stable version of Xamarin.Forms to every project
Give these steps a try in order—most folks fix this issue with the first two steps. Let me know if you still run into trouble!
内容的提问来源于stack exchange,提问作者Akmal Bukhariev

