Bug 18575 - Xamarin.Android runtime overrides custom OpenTK.dll
Summary: Xamarin.Android runtime overrides custom OpenTK.dll
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.12.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2014-03-25 13:26 UTC by BurnSpamAddress
Modified: 2017-06-29 19:22 UTC (History)
3 users (show)

Tags: bb
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 for Bug 18575 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description BurnSpamAddress 2014-03-25 13:26:55 UTC
While working on OpenGL ES 3.1 support in OpenTK, I came across a weird issue: Xamarin.Android will refuse to load the custom version of OpenTK. Instead, it will always load the built-in version. This behavior shows up in the form of TypeLoadExceptions when loading pretty much any type of the modified dll that doesn't also exist in the built-in dll.

- Changing the version number of the custom OpenTK.dll to e.g. does not make a difference.

- Changing the linker (link / don't link) or runtime options (shared / non-shared) does not make a difference.

- Changing the name of the assembly to something different, e.g. OpenTK.Custom.dll, results in the assembly loading as expected.

Is there a way to consume the modified dll without changing the assembly name? Changing the assembly name for development adds unnecessary noise to source control.
Comment 1 Shruti 2014-03-26 04:01:52 UTC
I have created new Android OpenGL Project. OpenTK is an inbuilt dll of Android   Application. As per my observation, Consumer is not allowed to change the version of inbuilt dll in Assembly browser. Can you provide more detail information where you tried to change the OpenTK.dll version.
Comment 2 BurnSpamAddress 2014-03-27 08:40:28 UTC
OpenTK is an open-source project. I am trying to merge the development histories of mono/opentk (included in Xamarin.Android) and opentk/opentk (upstream version).

This issue can be reproduced as follows:

1. Checkout OpenTK source code
git clone https://github.com/opentk/opentk
cd opentk
git checkout android-bug18575
git submodule init
git submodule update

2. Open OpenTK.mdw with Xamarin Studio

3. Right-click the OpenTK.Android.SDL2 solution and select "Start debugging"

4. The application will load on the device and immediately crash with a TypeLoadException

This is caused because Xamarin.Android is trying to load its built-in OpenTK.dll (v0.0.0.0) instead of the custom OpenTK.dll (v1.1.0.0). This happens even when I enable the "require specific version" option on the relevant reference.

I would expect Xamarin.Android to load the correct dll, as specified in the dll reference, instead of blindly loading the built-in version. Is there a workaround to achieve this without using a custom name?
Comment 3 Tom Opgenorth 2017-06-29 19:22:38 UTC
Thanks for the excellent reproduction steps. I tried to duplicate this with Visual Studio for Mac, but the build failed with the error 

error MSB3073: The command "mono ../../Binaries/Android/Debug/../../Tools/Debug/Rewrite.exe ../../Binaries/Android/Debug/OpenTK.Android.SDL2.dll ../../OpenTK.snk -debug" exited with code 1.`

I had to comment out a post build command in `OpenTK.Android.SDL2.csproj` (line 664):

<Exec Command="mono $(OutputPath)..\..\Tools\Debug\Rewrite.exe $(OutputPath)$(AssemblyName).dll ..\..\OpenTK.snk -debug" Condition="$(OS) != 'Windows_NT' and $(Configuration) == 'Debug'" />

After doing this, the project could build and run. When I run the application on an Android device then I get the exception:

{System.NotImplementedException: The method or operation is not implemented.   at OpenTK.Graphics.ES11.GL.ClearColor (System.Single red, System.Single green, System.Single blue, System.Single alpha) [0x00001] in /Users/tom/temp/opentk/Source/OpenTK/Graphics/ES1…}