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

Xamarin.Forms引用PCL引发Android平台System.IO.FileNotFoundException求助

Fixing System.IO.FileNotFoundException (System.Configuration) in Xamarin Android PCL Projects

Hey there, let's work through this annoying Android-only issue you're hitting. First, let's break down why this is happening:

This error pops up because of compatibility gaps between old PCL profiles and .NET Standard libraries, specifically when you reference a .NET Standard 2.0 class library in your Xamarin.Forms PCL project targeting .NET Framework 4.5. Mono for Android's runtime profile doesn't include the System.Configuration assembly by default, whereas iOS's runtime handles this reference differently—hence the platform-specific failure.

Here are the most effective fixes, ordered by how robust they are:

The cleanest long-term fix is to align your projects on .NET Standard 2.0:

  • Either recompile the referenced PCL library to target .NET Standard 2.0, or upgrade your Xamarin.Forms PCL project to .NET Standard 2.0.
  • To do this: Right-click the project → Properties → Application → Target framework, then select .NET Standard 2.0.
  • This eliminates the compatibility mismatch entirely, as .NET Standard is designed for cross-platform consistency. You might need to check for minor API differences, but .NET Standard 2.0 has excellent overlap with PCL profile 4.5.

2. Add the Official Configuration NuGet Package

If upgrading frameworks isn't feasible right now, install the official NuGet package to fill the gap:

  • In your Xamarin.Android project, install System.Configuration.ConfigurationManager via NuGet. This package provides the System.Configuration functionality for .NET Standard and Xamarin environments.
  • Once installed, the runtime will correctly resolve the assembly without throwing the FileNotFoundException.

3. Manually Reference the Assembly (Temporary Workaround)

If you prefer not to use NuGet, you can manually add the reference to your Android project:

  1. Right-click your Xamarin.Android project → Add → Reference.
  2. Go to the Assemblies tab, search for System.Configuration, and check the box to include it.
  3. Alternatively, edit your Android project's .csproj file to add this snippet (adjust the hint path to match your package version):
    <ItemGroup>
      <Reference Include="System.Configuration">
        <HintPath>..\packages\System.Configuration.ConfigurationManager.4.7.0\lib\netstandard2.0\System.Configuration.ConfigurationManager.dll</HintPath>
      </Reference>
    </ItemGroup>
    

4. Audit Hidden Dependencies

Sometimes System.Configuration is being pulled in indirectly by a third-party package in your referenced PCL:

  • Expand the Dependencies node in your project to trace which package is adding this reference.
  • Try replacing that package with a version that targets .NET Standard 2.0, or remove any unnecessary dependencies that aren't critical to your app.

内容的提问来源于stack exchange,提问作者Jorge MHT

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 08:59:52