5
votes

I'm trying to convert a PCL to .NET Standard 1.3 and failing. I've narrowed the failure down to a really simple example that I can't understand why it's failing.

I have a class that implements IMarkupExtension and simply compiling a project with just that class fails with:

The type 'IServiceProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Why on earth is it trying to pull in System.ComponentModel for a Xamarin Forms library that's using .NET Standard? It makes no sense to me.

The project references are as simple as you can get:

enter image description here

The class implementation couldn't be any simpler:

namespace OpenNETCF
{
    public sealed class ScaledDouble : IMarkupExtension
    {
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            return null;
        }
    }
}

I can get rid of the compiler error by manually editing the project file to include System.ComponentModel, but unsurprisingly the consuming app fails to load the type at runtime.

<ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="2.3.4.267" />

    <!-- Required for IMarkupExtension and IServiceProvider to compile.  No idea why. -->
    <PackageReference Include="System.ComponentModel" Version="4.3.0" />
</ItemGroup>

What's going on here??

1
Hmm, these are Silverlight interfaces. Check the compatibility chart. Silverlight is dead technology, development stopped in 2013.Hans Passant
Did you try installing this package?José Pedro

1 Answers

1
votes

.NET Standard projects doesn't have default assemblies. You should add reference or download from nuget.

PM> Install-Package System.ComponentModel