Bug 10407 - Android Callable Wrapper generator code does not properly support "intermediate" non-static inner classes from C#
Summary: Android Callable Wrapper generator code does not properly support "intermedia...
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.8.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Ankit Jain
URL:
Depends on:
Blocks:
 
Reported: 2013-02-18 22:57 UTC by jon
Modified: 2016-09-20 10:32 UTC (History)
4 users (show)

Tags: XATriaged
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description jon 2013-02-18 22:57:13 UTC
I am attempting to write an android live wallpaper using xamarin in c#. 
To do so, I converted the GLWallPaperService code found here into c#:
http://www.learnopengles.com/how-to-use-opengl-es-2-in-an-android-live-wallpaper/ 

(jump directly to java implementation here: https://github.com/learnopengles/Learn-OpenGLES-Tutorials/tree/master/android/AndroidOpenGLESLessons/src/com/learnopengles/android/livewallpaper) 

Upon compile, I get the error:

Activate(java.lang.String,java.lang.String,java.lang.Object,java.lang.Object[]) in mono.android.TypeManager cannot be applied to (java.lang.String,java.lang.String,com.[redacted].OpenGLES2WallpaperService.OpenGLES2WallpaperService_OpenGLES2Engine,java.lang.Object[]) mono.android.TypeManager.Activate ("com.[redacted].OpenGLES2WallpaperService/OpenGLES2Engine, GameUtilClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "com.[redacted].WallpaperServiceUtil.OpenGLES2WallpaperService, GameUtilClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", this, new java.lang.Object[] { OpenGLES2WallpaperService.this }); D:\[redacted]\obj\Debug\android\src\com\[redacted] \wallpaperserviceutil\OpenGLES2WallpaperService.java

Here is my c# implementation... sorry for the length:
public abstract class GLWallpaperService : WallpaperService
{
    public class GLEngine : Engine
    {
        private readonly GLWallpaperService outerInstance;

        public GLEngine(GLWallpaperService outerInstance) : base(outerInstance)
        {
            this.outerInstance = outerInstance;
        }

        internal class WallpaperGLSurfaceView : GLSurfaceView
        {
            private readonly GLWallpaperService.GLEngine outerInstance;
            ISurfaceHolder _surfaceHolder;

            internal WallpaperGLSurfaceView(GLWallpaperService.GLEngine outerInstance, Context context, ISurfaceHolder surfaceHolder)
                : base(context)
            {
                this.outerInstance = outerInstance;
                _surfaceHolder = surfaceHolder;
            }

            public override ISurfaceHolder Holder
            {
                get
                {
                    return _surfaceHolder;
                }
            }

            public virtual void OnDestroy()
            {
                base.OnDetachedFromWindow();
            }
        }

        private WallpaperGLSurfaceView glSurfaceView;
        private bool rendererHasBeenSet;

        public override void OnCreate(ISurfaceHolder surfaceHolder)
        {
            base.OnCreate(surfaceHolder);

            glSurfaceView = new WallpaperGLSurfaceView(this, outerInstance, surfaceHolder);
        }

        public override void OnVisibilityChanged(bool visible)
        {
            base.OnVisibilityChanged(visible);

            if (rendererHasBeenSet)
            {
                if (visible)
                {
                    glSurfaceView.OnResume();
                }
                else
                {
                    if (!IsPreview)
                    {
                        glSurfaceView.OnPause();
                    }
                }
            }
        }

        public override void OnDestroy()
        {
            base.OnDestroy();
            glSurfaceView.OnDestroy();
        }

        protected internal virtual Android.Opengl.GLSurfaceView.IRenderer NewRenderer//was just Renderer
        {
            set
            {
                glSurfaceView.SetRenderer(value);
                rendererHasBeenSet = true;
            }
        }

        protected internal virtual int EGLContextClientVersion
        {
            set
            {
                glSurfaceView.SetEGLContextClientVersion(value);
            }
        }
    }
}

public abstract class OpenGLES2WallpaperService : GLWallpaperService
{
    public override Engine OnCreateEngine()
    {
        return new OpenGLES2Engine(this);
    }

    internal class OpenGLES2Engine : GLWallpaperService.GLEngine
    {
        private readonly OpenGLES2WallpaperService outerInstance;

        public OpenGLES2Engine(OpenGLES2WallpaperService outerInstance)
            : base(outerInstance)
        {
            this.outerInstance = outerInstance;
        }

        public override void OnCreate(ISurfaceHolder surfaceHolder)
        {
            base.OnCreate(surfaceHolder);

            // Check if the system supports OpenGL ES 2.0.
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final android.app.ActivityManager activityManager = (android.app.ActivityManager) getSystemService(android.content.Context.ACTIVITY_SERVICE);
            ActivityManager activityManager = (ActivityManager)outerInstance.GetSystemService(Context.ActivityService);
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final android.content.pm.ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
            ConfigurationInfo configurationInfo = activityManager.DeviceConfigurationInfo;
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
            bool supportsEs2 = configurationInfo.ReqGlEsVersion >= 0x20000;

            if (supportsEs2)
            {
                // Request an OpenGL ES 2.0 compatible context.
                EGLContextClientVersion = 2;

                // Set the renderer to our user-defined renderer.
                NewRenderer = outerInstance.NewRenderer;//was just Renderer
            }
            else
            {
                // This is where you could create an OpenGL ES 1.x compatible
                // renderer if you wanted to support both ES 1 and ES 2.
                return;
            }
        }
    }

    internal abstract Android.Opengl.GLSurfaceView.IRenderer NewRenderer { get; }
}

public class LessonThreeWallpaperService : OpenGLES2WallpaperService
{
    internal override Android.Opengl.GLSurfaceView.IRenderer NewRenderer
    {
        get
        {
            return new LessonThreeRenderer(); // is a GLSurfaceView.IRenderer
        }
    }
}

I am targeting version sdk version 8 and using Visual Studio 2012. 

I was told that:
This is a bug in our Android Callable Wrapper generator code: we don't properly support "intermediate" non-static inner classes from C#. Specifically, `GLWallpaperService.Engine` is generated properly, but `OpenGLES2WallpaperService.OpenGLES2Engine` is not.

Please file a bug at https://bugzilla.xamarin.com.
Comment 1 dean.ellis 2016-09-20 10:32:01 UTC
Looking at the sample code in the latest versions of Xamarin.Android we do end up generating the following class

public class OpenGLES2WallpaperService_OpenGLES2Engine
	extends md5c178831cd46fc53bebc42cf953f78ced.GLWallpaperService.GLWallpaperService_GLEngine
	implements
		mono.android.IGCUserPeer
{
}

Which seems to be the missing class? 
I am going to close this bug as fixed. If this is not the case please reopen it and if possible provide a sample.