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

See Also:
Tags: bb
Is this bug a regression?: ---
Last known good build:


Attachments

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. 1.1.0.0 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 

`/Users/tom/temp/opentk/Projects/OpenTK.Android.SDL2/OpenTK.Android.SDL2.csproj(664,5): 
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…}

Note You need to log in before you can comment on or make changes to this bug.