Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

ResourceProvider Exception in Xamarin.Forms 3.0 due to Signature Change #2835

Closed
LanceMcCarthy opened this issue May 25, 2018 · 10 comments
Closed
Assignees
Labels
i/regression in-progress This issue has an associated pull request that may resolve it! t/bug 🐛

Comments

@LanceMcCarthy
Copy link

Description

Due to the change made in #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<System.String,System.String> 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<string, string> 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)

@PureWeen
Copy link
Contributor

PureWeen commented May 25, 2018

xamarin/xamarin-macios#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

@Szymaniuk
Copy link

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

@StephaneDelcroix
Copy link
Member

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

@LanceMcCarthy
Copy link
Author

I can confirm #2880 fixes the problem in my tests (attached repro and commercial 3rd party libraries).

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

image

@StephaneDelcroix
Copy link
Member

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

StephaneDelcroix added a commit that referenced this issue Jun 1, 2018
StephaneDelcroix added a commit that referenced this issue Jun 1, 2018
@LanceMcCarthy
Copy link
Author

@StephaneDelcroix confirmed working on iOS 11.4, iPhone 8

image

@avintoptaros
Copy link

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

@stephanosio
Copy link

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

@avintoptaros
Copy link

@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/)

@stephanosio
Copy link

mattleibow added a commit that referenced this issue Jan 6, 2019
 - initially added to resolve #2835
 - initially broken in #1594
@samhouts samhouts added the in-progress This issue has an associated pull request that may resolve it! label Jun 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i/regression in-progress This issue has an associated pull request that may resolve it! t/bug 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants