Bug 37302 - Getting different Android binding code generation results between Mac and Visual Studio
Summary: Getting different Android binding code generation results between Mac and Vis...
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 6.0.99
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2015-12-28 14:00 UTC by Roy Cornelissen
Modified: 2016-01-12 06:20 UTC (History)
1 user (show)

Tags:
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 Roy Cornelissen 2015-12-28 14:00:54 UTC
I'm working on bindings for the Kofax document scanning libraries. I'm getting different results on Visual Studio than on Xamarin Studio on the Mac when I compile my project. On Visual Studio, compilation breaks. The offending code in Visual Studio is:

static IntPtr n_GetBestPreviewSize_Ljava_util_List_II (IntPtr jnienv, IntPtr native__this, IntPtr native_p0, int p1, int p2)
{
    global::Com.Kofax.Mobile.Sdk._internal.Camera.IPreviewSizeDecider __this = global::Java.Lang.Object.GetObject<global::Com.Kofax.Mobile.Sdk._internal.Camera.IPreviewSizeDecider> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
    System.Collections.Generic.IList<Android.Graphics.Point> p0 = global::Android.Runtime.JavaList<global::Android.Graphics.Point>.FromJniHandle (native_p0, JniHandleOwnership.DoNotTransfer);
    IntPtr __ret = JNIEnv.ToLocalJniHandle (__this.GetBestPreviewSize (p0, p1, p2));
    return __ret;
}

And in Xamarin Studio, everything compiles fine, and the same generated method looks like this:

static IntPtr n_GetBestPreviewSize_Ljava_util_List_II (IntPtr jnienv, IntPtr native__this, IntPtr native_p0, int p1, int p2)
{
   global::Com.Kofax.Mobile.Sdk._internal.Camera.IPreviewSizeDecider __this = global::Java.Lang.Object.GetObject<global::Com.Kofax.Mobile.Sdk._internal.Camera.IPreviewSizeDecider> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
   var p0 = global::Android.Runtime.JavaList<global::Android.Graphics.Point>.FromJniHandle (native_p0, JniHandleOwnership.DoNotTransfer);
   IntPtr __ret = JNIEnv.ToLocalJniHandle (__this.GetBestPreviewSize (p0, p1, p2));
   return __ret;
}

The problem lies in the declaration of p0. The Kofax SDK uses a namespace called Com.Kofax.Android. This results in a clash with the generic type parameter for IList<Android.Graphics.Point> p0. Xamarin Studio generates a "var" declaration, Visual Studio leaves out "global::" to avoid the conflict.

I could fix this by renaming the managed namespace in Metadata.xml, but the difference in behavior is confusing.

The Kofax SDK is quite extensive and cannot be easily shared. Please let me know if you need the project for reproduction. I can send a private link.
Comment 1 Atsushi Eno 2016-01-05 08:42:28 UTC
Could you make sure that you are using the latest of either {alpha, beta or stable} that matches the version you are using on the Mac?
Different versions of the product will generate different binding code. We had fixed that kind of missing "global::Android" issues a couple of times in the past (including these months). I think your Xamarin.Android on Windows is old.
Comment 2 Roy Cornelissen 2016-01-11 07:13:07 UTC
Ah, thanks. That was indeed the issue. The dev environment at my customer's office is on an older Xamarin version. I'll keep the hacks in for now, but in the latest stable version this is not an issue anymore.
Comment 3 Atsushi Eno 2016-01-12 06:20:09 UTC
Sounds like it is already gone. If it happens on the latest version of {mentioned above} on Windows please reopen this. Thanks.