Xamarin.Forms编译报错:无法加载Windows.Foundation.FoundationContract程序集
Fixing "Windows.Foundation.FoundationContract" Not Found Error in Xamarin.Forms Android Project
Hey there, let's work through this frustrating error that's blocking your graduation project compilation. That missing Windows.Foundation.FoundationContract assembly is a UWP-specific component, so it shouldn't be showing up in your Android build at all. Here are the steps to resolve it:
1. Audit NuGet Packages in Your Android Project
- Right-click your Android project → Manage NuGet Packages
- Go to the Installed tab and look for any packages explicitly targeted at UWP, or packages with versions incompatible with your Xamarin.Forms setup.
- Try updating Xamarin.Forms to the latest stable version (make sure all your projects share the same version), and uninstall/reinstall any suspect packages that might be pulling in UWP dependencies.
2. Clean and Rebuild Thoroughly
- First, run Build → Clean Solution in Visual Studio.
- Manually delete the
binandobjfolders from your Android project (and shared project, if applicable) — this clears out cached build files that might be holding onto invalid references. - Finally, run Build → Rebuild Solution to start fresh.
3. Remove UWP-Specific References
- Right-click your Android project → References
- Scan the list for
Windows.Foundation.FoundationContractor any other UWP-related assemblies. If you find any, select them and click Remove — Android has no use for these.
4. Check Your Android Project File (.csproj)
- Sometimes invalid references linger in the project file even after removing them via the UI. Open your Android project's
.csprojfile in a text editor. - Search for any lines containing
Windows.Foundation.FoundationContract— if you find a<Reference>node for it, delete that entire line, save the file, and reload the project in Visual Studio.
5. Verify Your Xamarin.Android Environment
- Open Tools → Android → Android SDK Manager in Visual Studio.
- Ensure you have the latest Android SDK Platforms and Tools installed. Also, confirm that your Mono.Android version is compatible with your Xamarin.Forms version (check the Xamarin.Forms release notes for compatibility details).
6. Check Shared Project Dependencies
- If your shared code project (e.g., .NET Standard, PCL) is referencing UWP-specific libraries, those dependencies will trickle down to your Android project. Audit the references in your shared project and remove any UWP-only components that aren't necessary for cross-platform functionality.
If none of these steps work, it's possible a third-party library you're using is incorrectly including UWP references. In that case, you might need to look for an alternative library or check if the library has an update that fixes this issue.
Good luck with your graduation project — you've got this!
内容的提问来源于stack exchange,提问作者Lukas Klein Haneveld
相关产品推荐
相关产品推荐

