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

[Bug][XAML] Using an intermediate base class for a ResourceDictionary fails to load when XamlCompilation enabled #14972

@GalaxiaGuy

Description

@GalaxiaGuy

Description

For various reasons, we are trying to use a resource dictionary ColorResources, which inherits from a base class BaseResources which inherits from ResourceDictionary.

When XAML compilation is enabled InitializeComponent throws a null reference exception. Stepping into it, it seems to be because it is trying to add a Color as a Style.

If I use VS for Mac Assembly browser, I see the following in InitializeComponent which includes a suspicious Style cast towards the end:

[GeneratedCode ("Xamarin.Forms.Build.Tasks.XamlG", "2.0.0.0")]
private void InitializeComponent ()
{
	if (ResourceLoader.get_IsEnabled ()) {
		ResourceLoadingQuery val = new ResourceLoadingQuery ();
		val.set_AssemblyName (typeof(ColorResources).GetTypeInfo ().Assembly.GetName ());
		val.set_ResourcePath ("ColorResources.xaml");
		val.set_Instance ((object)this);
		if (ResourceLoader.CanProvideContentFor ((ResourceLoadingQuery)(object)val)) {
			__InitComponentRuntime ();
			return;
		}
	}
	if (XamlLoader.get_XamlFileProvider () != null && XamlLoader.get_XamlFileProvider () (base.GetType ()) != null) {
		__InitComponentRuntime ();
		return;
	}
	Color red = Color.Red;
	ColorResources colorResources;
	VisualDiagnostics.RegisterSourceInfo ((object)(colorResources = this), new Uri ("ColorResources.xaml" + ";assembly=" + "Bug", UriKind.RelativeOrAbsolute), 2, 2);
	NameScope val2 = (NameScope)(object)new NameScope ();
	((ResourceDictionary)colorResources).Add ((Style)(object)red);
}

Steps to Reproduce

  1. Create a ResourceDictionary subclass, and then a subclass of that.
  2. Enable XAML compilation
  3. Add something to the resource dictionary except a Style.
  4. Instantiate the subclass.

Expected Behavior

An instance of the subclass.

Actual Behavior

A null reference exception.

Basic Information

  • Version with issue: 5.0.0.1874
  • Last known good version: Unknown

Reproduction Link

https://github.com/GalaxiaGuy/xf-bugs/tree/bug/resource-dictionary

Workaround

Disabling XAML compilation makes the problem go away. Not having an intermediate class makes the problem go away.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions