Forum Cross Platform with Xamarin

Build errors when adding Microsoft.NETCore.Portable.Compatibility on a .Net Standard project

ThibaultDThibaultD SEMember ✭✭✭
edited January 2018 in Cross Platform with Xamarin


I am using Visual Studio Community Edition (Mac) v7.3.3.
I have recently created a new Xamarin.Forms application using a .Net Standard project instead of the legacy PCL project.
For this, I followed some guides out there but stumbled on a first issue. Luckily, @mattward came with an example on how to make my Android application project more .Net Core-like.
(Note: To this day, Visual Studio does not offer the possibility to create clean .Net Core-like iOS or Android projects, or I have missed it?)

But now bad luck strikes again as I am trying to add a PCL dependency (NControl) to my .Net Standard library.
After i add a reference to Microsoft.NETCore.Portable.Compatibility 1.0.1 in my .Net Standard project as explained by @JamesMontemagno in his video, the errors I get when building the Android application are:

CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: '/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/mscorlib.dll' and '/Users/username/.nuget/packages/microsoft.netcore.portable.compatibility/1.0.1/ref/netstandard1.0/mscorlib.dll'. Remove one of the duplicate references. [/Users/.../PclCompatBuildErrorsWithSystemComponentModel/Droid/PclCompatBuildErrorsWithSystemComponentModel.Droid.csproj]

As well as

Resources/Resource.designer.cs(12,36): error CS0731: The type forwarder for type 'System.Attribute' in assembly 'System.Runtime' causes a cycle [/Users/.../PclCompatBuildErrorsWithSystemComponentModel/Droid/PclCompatBuildErrorsWithSystemComponentModel.Droid.csproj]

And a several errors like:

Properties/AssemblyInfo.cs(21,12): error CS0246: The type or namespace name 'AssemblyVersion' could not be found (are you missing a using directive or an assembly reference?) [/Users/.../PclCompatBuildErrorsWithSystemComponentModel/Droid/PclCompatBuildErrorsWithSystemComponentModel.Droid.csproj]

And last but not least, thousands of errors like:

Resources/Resource.designer.cs(409,17): error CS0518: Predefined type 'System.Int32' is not defined or imported [/Users/.../PclCompatBuildErrorsWithSystemComponentModel/Droid/PclCompatBuildErrorsWithSystemComponentModel.Droid.csproj]

I created a repro-solution to isolate the problem and it seems to me that the problem is caused by the .NetCore-ification of my Android application project.

Adding Microsoft.NETCore.Portable.Compatibility 1.0.1 does not create any issue when using a legacy android application project (see repro project, branch legacy_droid_project)

But adding Microsoft.NETCore.Portable.Compatibility 1.0.1 after .NetCore-ification of my Android application project breaks the build (see repro project, branch master)

I've tried adding/removing dependencies,
I've tried to change the Android Target Framework version,
I've tried the "Do not reference mscorlib.dll" project option
And a few other fixes referenced when I searched for the error messages above but did not find anything working.

I'll be glad for any help, currently considering reverting my project to PCL.


  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    I am using Visual Studio Community Edition (Mac) v7.3.3.

    That's probably the first problem. I'd suggest you try all the same things, same steps on a Windows machine with VS2017.

    The Mac version of VS is far behind Windows. And probably always will be. The Windows edition has at about 15 years of head start.

    If you have a Windows machine, give that a go. If not, you can use VMwareFusion to install Windows onto your Mac. Or you can create a second boot drive and boot the mac into Window via BootCamp.

    If the problem persists in windows then its a problem with the ecosystem. If not, its a limitation of Visual Studio Mac. But until you can definitively point to where the problem is you're just groping in the dark.

Sign In or Register to comment.