I'm building a multi-platform class library with Xamarin. The Android project builds with no problem. But the iOS project gives me a bunch of errors like this, for various System
types:
error CS0012: The type 'System.IDisposable' is defined in an assembly that is not referenced. Consider adding a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
This happens regardless of whether I build via Visual Studio, or on the command line with msbuild
.
My .csproj has these framework references and package references:
<ItemGroup> <Reference Include="System" /> <Reference Include="System.Xml" /> <Reference Include="System.Core" /> <Reference Include="System.Net.Http" /> <Reference Include="Xamarin.iOS" /> <PackageReference Include="Common.Logging" Version="3.4.1" /> <PackageReference Include="Xamarin.Essentials" Version="0.8.0-preview" /> <PackageReference Include="Xam.Plugin.DeviceInfo" Version="4.0.0.13" /> <PackageReference Include="My.Other.Library" Version="1.0.2" /> </ItemGroup>
Note that My.Other.Library
is not an iOS project; it has targets of netstandard1.4
, netstandard1.6
, netstandard2.0
, and net45
. I'm guessing that that is not the problem, because the same library is also used by my Android project, which works fine.
Currently these two projects have the same code - that is, they both compile the same .cs
files from a shared directory, except for AssemblyInfo.cs
which exists separately in each project. They also have the same assembly references, except that the Android project uses Mono.Android
rather than Xamarin.iOS
.
I'm using Mac Visual Studio Community 7.5.2.
Any ideas?
Answers
Can you delete
<PackageReference Include="My.Other.Library" Version="1.0.2"
to test if error still exists?Indeed, it looks like the error only happens if I have the
My.Other.Library
reference. Every one of the errors I'm seeing is on a line where it refers to some type fromMy.Other.Library
, and the error always complains about not being able to find someSystem
type that that type refers to - for instance, if my type implementsIDisposable
it will say it can't findIDisposable
, and if there's nothing like that, it will say it can't find the base classObject
.But why this particular package should cause so much confusion for my iOS package - and only for iOS, not for Android - I have no idea.