I'm encountering this exception when linking to SDK assemblies and building the project:
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.
I've added Signalr.Client v. 3.1.2 for using Signalr in Xamarin.
Here's the 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" />
and here's the 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>
The project.assets.json file has two dependencies on older version of 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": {}
}
},
and
"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": {}
}
},
All others refer to 3.1.2 version.
Please help me on whether I should use any other versions of the packages, or maybe using "Skip linking assemblies" with any of them.
Thanks
The error message
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'.
and the entry in the 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": {}
}
},
shows that you still use an old asp.net core 2.2 reference.
The shared project shows were it is referenced:
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
and mixing it with 3.1.2 references
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="3.1.2" />
causes your issue.
Remove here the "Microsoft.AspNetCore.Mvc" entry to fix it.