Xamarin.Android项目安装NuGet包后出现程序集加载文件未找到异常
Hey there, let's walk through how to fix this assembly loading error you're facing after installing those NuGet packages. Given your specific setup (Xamarin.Forms v2.5.0.122203, VS2015 Pro, Mono.Android v6 targeting Android 6.0), here are the most actionable steps to diagnose and resolve the issue:
1. Verify NuGet Package Compatibility
Since you're working with older Xamarin versions, newly added packages might have dependencies that don't align with your environment:
- Open the NuGet Package Manager for your solution, go to the Installed tab, and sort packages by Installed Date to find the ones you recently added.
- For each of these packages, check their dependency requirements (look in the package details pane) to see if they demand a newer version of Mono.Android (v7+) or Xamarin.Forms than what you're using.
- If you spot an incompatible package, try downgrading it to a version that explicitly supports your framework versions, or temporarily uninstall it to see if the error goes away.
2. Clean & Rebuild Your Solution (with Manual Cache Deletion)
Build cache corruption is a common culprit for assembly loading issues:
- First, clean your solution via the IDE:
Build > Clean Solution - Navigate to your project's root directory manually and delete the
binandobjfolders (these hold cached build files that IDE cleanup might miss) - Finally, rebuild the solution:
Build > Rebuild Solution
3. Check for Broken Assembly References
Sometimes NuGet installations leave incomplete or invalid references:
- Right-click your Android project > Select References
- Look for any references marked with a yellow exclamation mark—this means the referenced assembly can't be found.
- If you find broken references, remove them (right-click >
Remove), then re-install the corresponding NuGet package to restore the correct reference.
4. Validate packages.config & AssemblyInfo.cs
Incorrect configuration files can lead to missing assemblies:
- Open your Android project's
packages.configfile. Ensure all installed NuGet packages are listed with the correct version numbers. If entries are missing or versions are wrong, correct them, then right-click your solution >Restore NuGet Packages - Check
Properties/AssemblyInfo.csfor any[assembly: UsesLibrary]attributes that reference libraries you don't have installed. Remove or update any invalid entries here.
5. Adjust Linker Settings
Older Xamarin.Android linker configurations might accidentally strip necessary assemblies:
- Right-click your Android project > Properties > Android Options > Linker
- Change the linker setting from
Sdk Assemblies OnlytoNone, then rebuild your project. If the error disappears, the linker was removing a critical dependency. You can then switch back toSdk Assemblies Onlyand add the required assemblies to the Skip linking assemblies list to preserve them.
6. Confirm Target/Minimum Android Version Alignment
Some NuGet packages require a minimum Android API level higher than your current 4.4 (API 20):
- Right-click your Android project > Properties > Android Manifest
- Check if any of your newly installed packages specify a minimum API level above 20. If so, you'll need to either raise your project's minimum Android version to match, or replace the package with one that supports API 20.
内容的提问来源于stack exchange,提问作者greenhoorn

