Xamarin.forms: ResourceProvider Exception in Xamarin.Forms 3.0 due to Signature Change

Created on 25 May 2018  路  10Comments  路  Source: xamarin/Xamarin.Forms

Description

Due to the change made in https://github.com/xamarin/Xamarin.Forms/pull/1976 for Xamarin.Forms 3.0, ResourceDictionaries that were compiled with XF 2.4 fail to load throwing the following exception:

Can't resolve the reference 'System.Func`2 Xamarin.Forms.Internals.ResourceLoader::get_ResourceProvider()', referenced from the method 'System.Void TheExternalResourceDictionary::InitializeComponent()' in 'Xamarin.Forms.Core

In particular, the ResourceDictionary in this case contains the styles for custom Xamarin.Forms controls that have a minimum support Xamarin.Forms version of 2.4

Steps to Reproduce

Download the simple repro using the link at the bottom of this post. Let me walk you through the two solutions:

  1. CustomControls - A simple class library with the ResourceDictionary
  2. ResLoaderRepro - The Xamarin.Forms runtime app that present the problem

image

1- CustomControls.sln (aka CoolGrid)

This is very simple class library that contains one class, CoolGrid, that inherits from Xamarin.Forms.Grid.

public class CoolGrid : Xamarin.Forms.Grid
    {
        public CoolGrid()
        {
            this.Resources = new CoolGridTheme();
        }
    }

The ResourceDictionary, "CoolGridTheme.xaml", is also very simple and contains a couple OnPlatform for height and a Style to set CoolGrid's BackgroundColor

<OnPlatform x:TypeArguments="x:Double" x:Key="Height" Default="32">
    <On Platform="Android" Value="45"/>
    <On Platform="iOS" Value="36"/>
    <On Platform="UWP" Value="32"/>
</OnPlatform>
<OnPlatform x:TypeArguments="x:Double" x:Key="MinimumHeight" Default="33">
    <On Platform="Android" Value="28"/>
    <On Platform="iOS" Value="28"/>
    <On Platform="UWP" Value="33"/>
</OnPlatform>

<Style x:Key="BaseCoolGridStyle" TargetType="customControls:CoolGrid">
    <Setter Property="HeightRequest" Value="{StaticResource Height}"/>
    <Setter Property="MinimumHeightRequest" Value="{StaticResource MinimumHeight}"/>
    <Setter Property="BackgroundColor" Value="DarkGray"/>
</Style>

The compiled result was copied to the Libs folder in the 2nd solution's folder.

2 - ResLoaderRepro.sln

This solution contains the Xamarin.Forms 3.0 projects (_created using the File > New > Xamarin.Forms app > Blank App template and only kept Android to keep it small_).

I updated the XF NuGet page to the latest public release and added the reference to the CustomControls assembly in the Libs folder.

Finally, on MainPage, I add a single instance of CoolGrid:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:customControls="clr-namespace:CustomControls;assembly=CustomControls"
             x:Class="ResLoaderRepro.MainPage">

    <StackLayout>
        <customControls:CoolGrid x:Name="MyCoolGrid" HeightRequest="100" WidthRequest="100"/>
    </StackLayout>
</ContentPage>

Here's a screenshot to better explain the simplicity of the setup:

image

Expected Behavior

The CoolGrid control will render.

Actual Behavior

An exception is thrown (see scrrenshot 4 below

System.MissingMethodException: System.Func`2 Xamarin.Forms.Internals.ResourceLoader.get_ResourceProvider()

Here's a screenshot of the break:

image

Basic Information

  • Version with issue:
  • Last known good version: v2.5.1.527436
  • IDE: VS2017 15.7.2
  • Platform Target Frameworks: All
  • Android Support Library Version: 23.3+
  • Nuget Packages: XF 3.0+

Screenshots

Screenshots inline with the explanation above.

Reproduction Link

Download the reproducible from here (3.1 MB)

regression in-progress bug

Most helpful comment

Any chance for quick fix? It's blocking me from updating my app to any Xamarin.Forms greater than 2.5.1.527436...

All 10 comments

https://github.com/xamarin/xamarin-macios/issues/3639

The solution here
https://bugzilla.xamarin.com/show_bug.cgi?id=60949
Was just to downgrade but that doesn't seem to work in your case

I also converted your project to netstandard since it was .net 4.5 just to see and same issue

Any chance for quick fix? It's blocking me from updating my app to any Xamarin.Forms greater than 2.5.1.527436...

I'm literally investigating this right now, but still can't tell if we'll be able to deliver a fix, nor can't I give you a time frame.

The workaround is to make sure all your dependencies are compiled against latest XF 3.0.0

I can confirm https://github.com/xamarin/Xamarin.Forms/pull/2880 fixes the problem in my tests (attached repro and commercial 3rd party libraries).

Repro Screenshot (using new Xamarin.Forms package containing fix):

image

@LanceMcCarthy could you also confirm it works on iOS ? thanks

@StephaneDelcroix confirmed working on iOS 11.4, iPhone 8

image

Hi @StephaneDelcroix , do you know when the next release will be with this fix? Thank you.

@avintoptaros It looks like the fix is already included in the release-3.0.0-sr3 and beta-3.1.0-pre3.

@stephanosio I see that on the release page there is no release-3.0.0-sr3 version (https://developer.xamarin.com/releases/xamarin-forms/xamarin-forms-3.0/)

Was this page helpful?
0 / 5 - 0 ratings