CS0234 error message: - Error CS0234 The type or namespace name 'GetRenderer' does not exist in the namespace 'Microsoft.Maui.Controls.Compatibility.Platform' (are you missing an assembly reference?)

wire_jp 216 Reputation points
2023-01-06T00:57:53.967+00:00

Hello,

I am porting some Xamarin code into .NET MAUI and I received the following error message error messages on lines 21, line 22, line 33, line 34, line 44 and line 50: -

Error CS0234 The type or namespace name 'GetRenderer' does not exist in the namespace 'Microsoft.Maui.Controls.Compatibility.Platform' (are you missing an assembly reference?)  


using Rg.Plugins.PopupMaui.iOS.Renderers;  
using Rg.Plugins.PopupMaui.Pages;  
using UIKit;  
using Microsoft.Maui.Controls.Compatibility.Platform.iOS;  
using Rg.Plugins.PopupMaui.Extensions;  
using OnPlatform = Microsoft.Maui.Controls.Compatibility.Platform;  
  
namespace Rg.Plugins.PopupMaui.iOS.Extensions  
{  
    internal static class PlatformExtension  
    {  
        private static bool IsiOS13OrNewer => UIDevice.CurrentDevice.CheckSystemVersion(13, 0);  
  
        public static IVisualElementRenderer GetOrCreateRenderer(this VisualElement bindable)  
        {  
  
  
            var renderer = OnPlatform.GetRenderer(bindable);  //CS0234 error  
            if (renderer == null)  
            {  
                renderer = OnPlatform.CreateRenderer(bindable);  //CS0234 error  
                OnPlatform.SetRenderer(bindable, renderer);   //CS0234 error  
            }  
            return renderer;  
        }  
  
        public static void DisposeModelAndChildrenRenderers(this VisualElement view)  
        {  
            IVisualElementRenderer renderer;  
#pragma warning disable CS0618 // Type or member is obsolete  
            foreach (var child in view.RgDescendants().OfType<VisualElement>())  
            {  
                renderer = OnPlatform.GetRenderer(child);  //CS0234 error  
                OnPlatform.SetRenderer(child, null);   //CS0234 error  
  
                if (renderer == null)  
                    continue;  
  
                renderer.NativeView.RemoveFromSuperview();  
                renderer.Dispose();  
            }  
#pragma warning restore CS0618 // Type or member is obsolete  
  
            renderer = OnPlatform.GetRenderer(view);   //CS0234 error  
            if (renderer != null)  
            {  
                renderer.NativeView.RemoveFromSuperview();    
                renderer.Dispose();  
            }  
            OnPlatform.SetRenderer(view, null); //CS0234 error  
        }  

Kindly help me to fix the CS0234 error messages

Developer technologies | .NET | .NET MAUI
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2023-01-06T09:59:38.883+00:00

    Hello,

    In MAUI, some render classes are replaced by handlers, you can try to use Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer.

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.