You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xamarin.Forms迁移至.NET Standard后启动抛TypeLoadException求助

Troubleshooting TypeLoadException After Xamarin.Forms Portable → .NET Standard Migration

Hey there, let's tackle this TypeLoadException issue you're hitting after migrating your Xamarin.Forms app from Portable to .NET Standard. I've dealt with similar migration headaches before, so here are some actionable steps to help you get to the bottom of it:

  • Check for Assembly Version Mismatches
    TypeLoadExceptions often stem from conflicting package versions between your .NET Standard library and platform projects (Droid/iOS). First, make sure all Xamarin.Forms NuGet packages are on the exact same version across every project. Run dotnet list package in each project's directory to spot discrepancies, then update them to match. Also, double-check that any third-party libraries you use are compatible with .NET Standard—some older PCL-focused packages might not play nicely with the newer framework.

  • Dig Into the Full Exception Details
    Don't stop at the top-level TypeLoadException. Look for the inner exception or full stack trace—it'll almost always tell you exactly which type it can't load, and why (like a missing method or incompatible assembly version). You can grab this by attaching a debugger when launching your Droid/iOS project, or checking device logs: use adb logcat for Android, or the Xcode organizer for iOS.

  • Do a Full Clean & Rebuild
    Old build artifacts from your PCL days might be lingering and causing conflicts. Follow these steps:

    1. Right-click your solution → Clean Solution
    2. Delete the bin and obj folders from all projects (yes, even the platform-specific ones)
    3. Rebuild the solution from scratch, starting with the .NET Standard library first, then your Droid and iOS projects.
  • Audit for PCL-Specific or Obsolete Code
    Some APIs that worked in PCLs aren't available in .NET Standard. For example, if you were using a PCL version of System.Threading.Tasks.Extensions, you'll need to switch to the official .NET Standard package. Go through your code and pay attention to compiler warnings about obsolete or unsupported types—those are usually the culprits.

  • Verify Platform Project Configurations

    • Android: Check that your .csproj has the correct target framework (e.g., net7.0-android) and that <AndroidUseLatestPlatformSdk> is set to true. Also, confirm your .NET Standard library is referenced correctly (no broken icons in Solution Explorer).
    • iOS: Ensure your target iOS version is compatible with your .NET Standard library version. Temporarily set Linker Behavior to Don't Link to test if the linker is stripping out necessary types (this is a common gotcha).
  • Look for Duplicate Assemblies
    Sometimes multiple copies of the same assembly (with different versions) end up in the output folder. Use a tool like ILSpy to inspect your app's output directory (for Android, it's bin/Debug/net7.0-android/apk/assemblies) and check for duplicate DLLs. If you find any, track down their source (NuGet packages or project references) and resolve the conflict.

If none of these steps fix the issue, sharing the full stack trace of the exception would help narrow things down even further.

内容的提问来源于stack exchange,提问作者Russell de Pina

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:11:20