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.
Originally posted at the xamarin forums: https://forums.xamarin.com/discussion/72639/implementing-java-interfaces-without-inheriting-java-lang-object-should-fail-early#latest
Jonathan Dick asked me for posting it here again (https://twitter.com/redth/status/867509147062988800)
So here we go:
On stack overflow I answered some questions (e.g. http://stackoverflow.com/questions/38706366/interface-implement-differences-in-c-sharp-vs-java/38707255#38707255 ) where not inheriting from Java.Lang.Object was the cause of the problem. The main problem is, that nobody sees the message on the build output.
> Type 'MyListener ' implements Android.Runtime.IJavaObject but does not inherit from Java.Lang.Object. It is not supported.
Usually the interface is implemented with Handle and Dispose like:
public class SomeImplementation : ISomeJavaInterface
public IntPtr Handle
throw new NotImplementedException();
public void Dispose()
throw new NotImplementedException();
I've added a Stackoverflow documentation for it: http://stackoverflow.com/documentation/xamarin.android/771/bindings/18058/implementing-java-interfaces
I'm wondering if there is any reason for not failing early with a compiler error!? If not, this should be changed :)
This warning most certainly should become a build error. Since it cannot be really made into a compilation error I'm reassigning the bug to the build system which can capture the message and convert it to an error.
> I'm wondering if there is any reason for not failing early with a compiler error
Yes: compatibility. We "discovered" and raised this as a warning several *years* after initial release, and without knowing how much code this would impact, had -- and still have -- no idea how many projects would suddenly stop building if this warning were made an error. (The warning was added to source control in August 2013; Mono for Android 1.0 was released in 2011.)
"Pick your poison," as they say...
Additionally, this isn't limited to just source code in a project. *ANY* e.g. NuGet package or other library your App Project references could also run afoul of this.
Yes, you shouldn't do that, but wholesale changing everything is...scary, frankly.
@Dean: While this should be an error, we should also add a new MSBuild property to *disable* emitting the error, in case some project which is currently working is working *in spite of this warning.* That way if a project "suddenly breaks," there's something they can do about it.
I am confirming this behavior based on comments:
This is a common issue that Xamarin.Android developers run into because things like View.IOnClickListener(https://developer.xamarin.com/api/type/Android.Views.View+IOnClickListener/) implement `IJavaObject` but do not inherit from `Java.Lang.Object`. Thus the developer who implements an interface like View.IOnClickListener needs to ensure they inherit `Java.Lang.Object`.
An optional MSBuild property can definitely help identify more cases and ultimately help fix issues in projects, libraries, etc.
This is a more involved fix than at first thought. Moving to the 15.5 milestone.