链接时出现 IAuthenticationHandler 错误 XA2006

error XA2006 with IAuthenticationHandler when linking

我在链接到 SDK 程序集和构建项目时遇到此异常:

Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'Microsoft.AspNetCore.Http.Features.Authentication.IAuthenticationHandler' (defined in assembly 'Microsoft.AspNetCore.Http, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60') with scope 'Microsoft.AspNetCore.Http.Features, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. When the scope is different from the defining assembly, it usually means that the type is forwarded.

我添加了 Signalr.Client v. 3.1.2 以便在 Xamarin 中使用 Signalr。

这是 PCL csproj:

<PackageReference Include="Fody" Version="6.1.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Forms.Controls.FlexButton" Version="0.11.0" />
    <PackageReference Include="Microsoft.AppCenter" Version="3.0.0" />
    <PackageReference Include="Microsoft.AppCenter.Analytics" Version="3.0.0" />
    <PackageReference Include="Microsoft.AppCenter.Crashes" Version="3.0.0" />
    <PackageReference Include="Microsoft.AppCenter.Push" Version="3.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="3.1.2" />
    <PackageReference Include="Plugin.XSnack" Version="1.0.17" />
    <PackageReference Include="PropertyChanged.Fody" Version="3.2.6" />
    <PackageReference Include="Rg.Plugins.Popup" Version="1.2.0.223" />
    <PackageReference Include="sqlite-net-pcl" Version="1.6.292" />
    <PackageReference Include="Xam.Plugin.Media" Version="4.0.1.5" />
    <PackageReference Include="Xamanimation" Version="1.3.0" />
    <PackageReference Include="Xamarin.FFImageLoading" Version="2.4.11.982" />
    <PackageReference Include="Xamarin.FFImageLoading.Forms" Version="2.4.11.982" />
    <PackageReference Include="Xamarin.FFImageLoading.Transformations" Version="2.4.11.982" />
    <PackageReference Include="Xamarin.Forms" Version="4.5.0.356" />
    <PackageReference Include="Xamarin.Essentials" Version="1.5.1" />
    <PackageReference Include="Xamarin.Forms.RangeSlider" Version="1.0.2" />
    <PackageReference Include="Xamarin.Forms.Visual.Material" Version="4.5.0.356" />
    <PackageReference Include="XamForms.HtmlLabel" Version="1.0.0" />

这是 Xamarin Android csproj:

<PackageReference Include="Forms.Controls.FlexButton">
      <Version>0.11.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AppCenter">
      <Version>3.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AppCenter.Analytics">
      <Version>3.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AppCenter.Crashes">
      <Version>3.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AppCenter.Push">
      <Version>3.0.0</Version>
    </PackageReference>
    <PackageReference Include="Rg.Plugins.Popup">
      <Version>1.2.0.223</Version>
    </PackageReference>
    <PackageReference Include="Xam.Plugin.Media">
      <Version>4.0.1.5</Version>
    </PackageReference>
    <PackageReference Include="Xamanimation">
      <Version>1.3.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.FFImageLoading">
      <Version>2.4.11.982</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.FFImageLoading.Forms">
      <Version>2.4.11.982</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.FFImageLoading.Transformations">
      <Version>2.4.11.982</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms" Version="4.5.0.356" />
    <PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
    <PackageReference Include="Xamarin.Essentials" Version="1.5.1" />
    <PackageReference Include="Xamarin.Forms.RangeSlider">
      <Version>1.0.2</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms.Visual.Material">
      <Version>4.5.0.356</Version>
    </PackageReference>
    <PackageReference Include="XamForms.HtmlLabel">
      <Version>1.0.0</Version>
    </PackageReference>

project.assets.json 文件对 Microsoft.AspNetCore.Http.Features

的旧版本有两个依赖项
"Microsoft.AspNetCore.Http.Abstractions/2.2.0": {
  "type": "package",
  "dependencies": {
    "Microsoft.AspNetCore.Http.Features": "2.2.0",
    "System.Text.Encodings.Web": "4.5.0"
  },
  "compile": {
    "lib/netstandard2.0/Microsoft.AspNetCore.Http.Abstractions.dll": {}
  },
  "runtime": {
    "lib/netstandard2.0/Microsoft.AspNetCore.Http.Abstractions.dll": {}
  }
},

"Microsoft.AspNetCore.Hosting.Server.Abstractions/2.2.0": {
  "type": "package",
  "dependencies": {
    "Microsoft.AspNetCore.Http.Features": "2.2.0",
    "Microsoft.Extensions.Configuration.Abstractions": "2.2.0"
  },
  "compile": {
    "lib/netstandard2.0/Microsoft.AspNetCore.Hosting.Server.Abstractions.dll": {}
  },
  "runtime": {
    "lib/netstandard2.0/Microsoft.AspNetCore.Hosting.Server.Abstractions.dll": {}
  }
},

其他参考3.1.2版本

请帮助我确定是否应该使用任何其他版本的软件包,或者是否应该将 "Skip linking assemblies" 与其中任何一个一起使用。

谢谢

错误信息

error XA2006: Could not resolve reference to 'Microsoft.AspNetCore.Http.Features.Authentication.IAuthenticationHandler' (defined in assembly 'Microsoft.AspNetCore.Http, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60') with scope 'Microsoft.AspNetCore.Http.Features, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

和 project.assets.json 中的条目:

"Microsoft.AspNetCore.Http.Abstractions/2.2.0": {
  "type": "package",
  "dependencies": {
    "Microsoft.AspNetCore.Http.Features": "2.2.0",
    "System.Text.Encodings.Web": "4.5.0"
  },
  "compile": {
    "lib/netstandard2.0/Microsoft.AspNetCore.Http.Abstractions.dll": {}
  },
  "runtime": {
    "lib/netstandard2.0/Microsoft.AspNetCore.Http.Abstractions.dll": {}
  }
},

表明您仍在使用旧的 asp.net 核心 2.2 参考。

shared project 显示它是否被引用:

<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />

并将其与 3.1.2 参考文献混合

<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="3.1.2" />

导致您的问题。

在此处删除 "Microsoft.AspNetCore.Mvc" 条目以修复它。