Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Can't Resolve Platform Effect in Xamarin Forms component

$
0
0

I don't normally like posting in two places, but since my thread on SO has gone unanswered, I'm hoping that someone who can help sees this here. If I do receive an answer here or on SO I will make sure to update the other thread.

Copied from that thread:


I am having issues with Platform Effects in Xamarin Forms. These effects worked in a shared library format, and we are now migrating to .NET Standard 2.0 for reasons outside of the scope of this post.

Project Setup

  • VS 2017 15.8.0
  • Xamarin Forms 3.1.0.697729
  • Two .Net Standard 2.0 projects (one is for components, the other for the main UI)
  • Two Android projects (one that runs, the other is an Android .dll)
  • Two iOS projects (same deal)

Main Issue: None of my platform effects in the Android .dll work. They all resolve as null effect.

According to the documentation, my setup is correct. (Microsoft documentation on effects. Cannot post links.)

I found two different issues and have hit a brick wall.

  1. When I follow the instructions exactly and place [assembly: ResolutionGroupName("MyGroupName")] on the platform renderer itself, I get exceptions with Xamarin's dependency resolver. There is no message, just an exception and stack trace that leads back to the constructor of the RoutingEffect.
  2. When I use a slightly different pattern and register that on the namespace of an empty file in my .NET Standard 2.0 project, all effects return as null effect.

I've been Googling and digging through forums to no avail. Does anyone have an idea what could be the problem?

Side notes: All of the custom renderers work after using the static Init() trick, but not the effects. I have also tried making the typeof() statement reference both the Android version of the class and the .NET Standard 2.0 version of the class.

For the sake of completeness, here's what I have going.

NET Standard 2.0:

    namespace MyBaseNamespace.Components.Effects
    {
        public class SearchBarStylingEffect : RoutingEffect
        {
            public SearchBarStylingEffect() : base("MyGroupName.SearchBarStylingEffect")
            {
            }
        }
    }

Android:

[assembly: ResolutionGroupName("MyGroupName")]
[assembly: ExportEffect(typeof(SearchBarStylingEffect), "SearchBarStylingEffect")]
namespace MyBaseNamespace.Components.Android.Renderers.Effects
{
    public class SearchBarStylingEffect : PlatformEffect
    {
      …
    }
}

(iOS is the same as Android, only the namespace is different)


NOTE: The SO thread has the same title and is tagged with Xamarin.Forms. I don't have link permissions, so this is the best I can do.

EDIT: Removed gigantic header for "Copied from that thread".


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>