Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IServiceProvider not available in .NET Standard?

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??

like image 767
ctacke Avatar asked Nov 07 '22 17:11

ctacke


1 Answers

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

PM> Install-Package System.ComponentModel

like image 81
Nuri YILMAZ Avatar answered Nov 29 '22 10:11

Nuri YILMAZ