Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
I get an InvalidCastException when I cast the IGL10 object that is passed to the OnSurfaceCreated method of a GLSurfaceView.IRenderer to an IGL11ExtensionPack.
This is the standard Android mechanism for using the extension pack methods as far as I'm aware.
This makes it impossible for me to use any of the extension methods in the IGL11ExtensionPack, generating a RenderBuffer using the GlGenRenderbuffersOES() method, for example.
I've attached a modified version of the API Demo sample solution that will reproduce the error. Simply deploy the solution and go to Graphics/SurfaceView Overlay
Here's the stack trace:
System.InvalidCastException: Cannot cast from source type to destination type.
at MonoDroid.ApiDemo.CubeRenderer.OnSurfaceCreated (Javax.Microedition.Khronos.Opengles.IGL10,Javax.Microedition.Khronos.Egl.EGLConfig) [0x00001] in /Users/i53143/workspaces/monodroid-samples-master/ApiDemo/Graphics/CubeRenderer.cs:93
at Android.Opengl.GLSurfaceView/IRendererInvoker.n_OnSurfaceCreated_Ljavax_microedition_khronos_opengles_GL10_Ljavax_microedition_khronos_egl_EGLConfig_ (intptr,intptr,intptr,intptr) [0x00019] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/7f0e3d3c/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Opengl.GLSurfaceView.cs:551
at at (wrapper dynamic-method) object.7a2fe63c-8392-4ad0-afe2-a3b7b073ed68 (intptr,intptr,intptr,intptr) <IL 0x0001d, 0x0004b>
How do you actually cast? If you use JavaCast<T>() and still seeing InvalidCastException please provide some reproducible code that causes the problem.
Created attachment 6581 [details]
Modified ApiDemo sample code
I guess the attachment didn't save when I created the bug.
// At this point we get a class cast exception
IGL11ExtensionPack ext = (IGL11ExtensionPack)gl;
As I wrote earlier, JavaCast<T>() is required. You cannot use C# cast.
The code above must be:
IGL11ExtensionPack ext = gl.JavaCast<IGL11ExtensionPack>();
(And add "using Java.Interop;" to actually use that extension method.)