question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compatibility: (Revised) Ported Xamarin Forms Effect registration never resolves

See original GitHub issue

Description

While testing a newly ported custom ColorPicker, I ported the control’s touch handling in ColorPickerTouchEffect, which consists of the platform-independent ColorPickerTouchRoutingEffect and the platform-specific ColorPickerTouchEffectXXXX, where XXXX is platform specific (WinUI, Droid, etc) currently being implemented.

During my testing I set breakpoints in each of the Configure… builder calls in MauiProgram and discovered that ConfigureEffects fails to register the PlatformEffect. Both ConfigureFonts and ConfigureMauiHandlers are called as expected. I confirmed that ConfigureEffects IS called because the EffectsFactory and EffectsRegistration are in the builder.

AddCompatibilityEffects, which performs assembly scanning, never resolves the PlatformEffect.

Here is the initialization code:


    public static MauiApp CreateMauiApp()
    { 
        var builder = MauiApp.CreateBuilder();

        builder.UseMauiApp<App>();
        builder.UseSkiaSharp( true );

        builder.ConfigureMauiHandlers( handlers =>
        {
            handlers.TryAddCompatibilityRenderer( typeof( ColorCircle ), typeof( ColorCircle ) );
            handlers.TryAddCompatibilityRenderer( typeof( ColorWheel ), typeof( ColorWheel ) );
            handlers.TryAddCompatibilityRenderer( typeof( ColorTriangle ), typeof( ColorTriangle ) );
            handlers.TryAddCompatibilityRenderer( typeof( AlphaSlider ), typeof( AlphaSlider ) );
            handlers.TryAddCompatibilityRenderer( typeof( LuminositySlider ), typeof( LuminositySlider ) );
            handlers.TryAddCompatibilityRenderer( typeof( RGBSliders ), typeof( RGBSliders ) );
            handlers.TryAddCompatibilityRenderer( typeof( HSLSliders ), typeof( HSLSliders ) );
        } );

        builder.ConfigureFonts( fonts =>
        {
            fonts.AddFont( "OpenSans-Regular.ttf", "OpenSansRegular" );
        } );

        builder.ConfigureEffects( effects =>
        {
            var assemblies = Device.GetAssemblies();
            effects.AddCompatibilityEffects( assemblies );
        } );

        return builder.Build();

Steps to Reproduce

  1. Port an XF application that includes an Effect
  2. Add builder.ConfigureEffects to MauiProgram to register Effects
  3. Launch the application
  4. Observe a NRE because the PlatformEffect was not atttached to the RoutingEffect which should occur during Effect resolution.

Version with bug

Preview 12 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

Android 12 and up, Windows SDK 10.0.19041

Did you find any workaround?

Not yet, although I’m still working on it. I filed this because Shane recommended that I do so.

Subsequent debugging revealed that ConfigureEffects is working correctly. Still tracking down why the registration function, AddCompatibilityEffects, doesn’t resolve the Effect.

Relevant log output

None

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
IndianaGarycommented, May 11, 2022

Thanks for following up. With no movement on the issue I choose to abandon Effects and converted the code to a Behavior which uses a different (and simpler) mechanism. As the Behavior performs the requisite services perfectly, I am abandoning Effects for now.

0reactions
samhoutscommented, May 12, 2022

@IndianaGary Sorry for the delay getting back to you! I’ll close this for now, but please let us know if you come across further issues. Thank you!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xamarin.Forms DependencyService Registration and ...
Invoking a platform implementation that hasn't been registered with the DependencyService will result in a NullReferenceException being thrown.
Read more >
Xamarin Community Forums - RSSing.com
Unable to resolve dependencies. 'Xamarin.Android.Support.v7.AppCompat 23.4.0.1' is not compatible with 'Xamarin.Android.Support.Design 23.4.0.1 constraint ...
Read more >
Search existing .NET feedback
This problem arose after upgrading to .NET Core 3.0 fresh as of today. When creating any new 3.0 project, even a simple console,...
Read more >
What Makes .NET Core So Special?
I'm in the process of porting a bunch of go code to dotnet core 2.1 on AWS lambda. I'm on a Mac using...
Read more >
Multiplatform UI Coding with AvaloniaUI in Easy Samples. ...
Avalonia is a great new multiplatform UI package similar but in many respects better than WPF. This is an introductory tutorial article.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found