title: Xamarin Forms Display image from Embedded resource using XAML
body: <p>I'm trying to display and embedded image in a shared project resource (as explained <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=vswin" rel="noreferrer">here</a> on microsoft documentation).  </p>
  
  <p>I created the ImageResourceExtension, the project compiles, but I get the following error when I start the project : </p>
  
  <blockquote>
    <p>Could not load type 'Xamarin.Forms.Xaml.IReferenceProvider' from
    assembly 'Xamarin.Forms.Core, Version=2.0.0.0</p>
  </blockquote>
  
  <p>Here's my code :</p>
  
  <p>MainPage.xaml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               xmlns:local="clr-namespace:App1"
               x:Class="App1.MainPage"&gt;
  
      &lt;StackLayout&gt;
  
          &lt;Image x:Name="imgTest" Source="{local:ImageResource img.jpg}" /&gt;
  
      &lt;/StackLayout&gt;
  
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p>EmbeddedImage.cs</p>
  
  <pre><code>namespace App1
  {
      [ContentProperty(nameof(Source))]
      public class ImageResourceExtension : IMarkupExtension
      {
          public string Source { get; set; }
  
          public object ProvideValue(IServiceProvider serviceProvider)
          {
              if (Source == null)
                  return null;
  
              // Do your translation lookup here, using whatever method you require
              var imageSource = ImageSource.FromResource(Source, typeof(ImageResourceExtension).GetTypeInfo().Assembly);
  
              return imageSource;
          }
      }
  }
  </code></pre>