2
votes

I'm getting an error when creating a blank Xamarin.Forms project in VS where the netstandard assembly isn't being referenced, and cannot for the life of me figure out how to fix it.

The errors I'm getting in the app are:

  • CS0012 C# The type is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51'
  • CS0006 C# Metadata file '..\bin\Debug\netstandard2.0\ref\App.dll' could not be found)

I have tried, to no avail:

  • Updating the NETStandard.Library package to 2.0 or higher through NuGet (works for the App.iOS and App.Android projects but not the main App - it says "Blocked by project" for anything above v1.6.1)
  • Adding a reference to the requested netstandard version in the csproj <Reference Include="netstandard"/> as suggested here: https://github.com/dotnet/standard/issues/542#issuecomment-344591026
  • Adding <Reference Include="System.IdentityModel"/> to the csproj as suggested here: https://github.com/dotnet/standard/issues/542#issuecomment-501309019
  • Changing <TargetFramework>netstandard2.0</TargetFramework> to
    <TargetFrameworks>netstandard2.0</TargetFrameworks> as suggested here: https://github.com/dotnet/standard/issues/542#issuecomment-465375220
  • Deleting the bin, obj, .suo, and .vs folders and restarting VS, as well as creating an entirely new Xamarin.Forms blank project
  • Updating Xamarin.Essentials and Xamarin.Forms in NuGet
  • Updating to VS Community 2019 16.5.0 Preview 2.0 (where I'd read this issue had been fixed; I've unfortunately misplaced the thread this was in)

This is my csproj (default with the exception of the AutoGenerateBindingRedirects, which was suggested in the comments):

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <ProduceReferenceAssembly>true</ProduceReferenceAssembly>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>portable</DebugType>
    <DebugSymbols>true</DebugSymbols>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.3.0.908675" />
    <PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="ViewModels\" />
  </ItemGroup>
</Project>

Anyone have any idea what to do about this? Most of the answers I've found either don't work or are several years old and are alleged to have been fixed with newer VS versions.

Here's a link to my detailed output logs:

VS Community 19 Preview: https://privatebin.net/?c7c4cd6123e0edd7#5qYTwaKSyGKBMgU3beshk3Xgx52nyCyAYcsq63uRfWWT

VS Community 19: https://privatebin.net/?2cf9d7ab07e8a4fb#5UkwWhxKFPDGnTtVdZuawkQLMRNe4qvJLeuaBrFrPoJf

1
which windows 10 version do you use? update your windows 10 to 1909magicandre1981
I am already on 1909.kaci
delete obj/bin folders and reopen solution. the "PackageReference Include" thing is buggy as hell.magicandre1981
Ah, sorry, forgot to say I've tried that already also, hasn't helped unfortunately but I'll edit my question to reflect that.kaci
sometimes simply closing a solution and reopen helps.magicandre1981

1 Answers

5
votes

Found the problem after two weeks of personal suffering and 2 hours spent with someone experienced with Xamarin! The issue was that I had two different versions of dotnet installed (one in the C: drive and one in my E: drive where I also keep program files). Entered dotnet --version in cmd only to see that the version it found was Ancient (1.x), and then dotnet --list-sdks to find the duplicate one. After deleting the old SDK in the E: drive and rechecking my dotnet version the error vanished!