Bug 41319 - registrar generated code leads to "'initWithCoder:' has been explicitly marked unavailable"
Summary: registrar generated code leads to "'initWithCoder:' has been explicitly marke...
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: XI 9.8 (tvOS / C7)
Hardware: PC All
: High major
Target Milestone: C7SR1
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
: 41637 41650 41730 42555 ()
Depends on:
Blocks:
 
Reported: 2016-05-25 19:14 UTC by Mohit Kheterpal
Modified: 2016-07-15 09:33 UTC (History)
15 users (show)

Tags:
Is this bug a regression?: Yes
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:
VERIFIED FIXED

Comment 1 Sebastien Pouliot 2016-05-25 19:32:40 UTC
That's a sample issue

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIActivityViewController.h:23:1: note: 'initWithCoder:' has been explicitly marked unavailable here
		- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;

^ it's trying to subclass a type using an API that Apple marked as unavailable.
Comment 2 Sebastien Pouliot 2016-05-25 20:17:59 UTC
moving sample issue out of the current milestone
Comment 3 Sebastien Pouliot 2016-06-08 21:46:29 UTC
This was not an issue in the sample.
Comment 4 Sebastien Pouliot 2016-06-08 21:49:53 UTC
Having a constructor with

> [Export("initWithCoder:")]

to conform to NSCoding trigger the error.

It's unclear how `clang` ends up with the `NS_UNAVAILABLE` of `UIActivityViewController`.
Comment 5 Sebastien Pouliot 2016-06-08 22:00:11 UTC
Discarding the _reported_ error, the _real_ error seems to be the _warning_

/Users/poupou/git/xamarin/monotouch-samples/ios8/Lister/ListerToday/obj/iPhone/Debug/mtouch-cache/registrar.m:1753:16: warning: 'NSObject' may not respond to 'initWithCoder:'
		                        rv = [super initWithCoder:p0];
		                              ~~~~~ ^

`NSObject` does not, itself, conforms to `NSCoding`, so the generated code should not call `initWithCoder:`.
Comment 6 Rolf Bjarne Kvinge [MSFT] 2016-06-08 22:05:56 UTC
There seems to be at least one clang bug here, because the error shows up with this code:

> #import <UIKit/UIKit.h>

> @interface List : NSObject {
> }
> 	-(id) initWithCoder:(NSCoder *)p0;
> @end
> @implementation List { }
> 	-(id) initWithCoder:(NSCoder *)p0
> 	{
> 		return [super initWithCoder:p0];
> 	}
> @end

Sebastien is right though, we should not call super here in the first place.
Comment 7 Rolf Bjarne Kvinge [MSFT] 2016-06-08 22:22:45 UTC
The fix for bug #35458 introduced this.

Clang bug filed: https://llvm.org/bugs/show_bug.cgi?id=28058
Comment 8 Sebastien Pouliot 2016-06-08 22:33:26 UTC
A possible workaround would be to remove the `[Export("initWithCoder:")]` from the C# code. As long as the type is not created from native code then it should be fine.
Comment 9 Rolf Bjarne Kvinge [MSFT] 2016-06-09 09:13:48 UTC
*** Bug 41637 has been marked as a duplicate of this bug. ***
Comment 10 Rolf Bjarne Kvinge [MSFT] 2016-06-09 09:14:36 UTC
This was confirmed to be a clang bug (which doesn't change anything for us, we'll still have to fix/work around it ourselves).
Comment 11 Rolf Bjarne Kvinge [MSFT] 2016-06-09 12:33:15 UTC
*** Bug 41650 has been marked as a duplicate of this bug. ***
Comment 15 Rolf Bjarne Kvinge [MSFT] 2016-06-14 05:57:57 UTC
*** Bug 41730 has been marked as a duplicate of this bug. ***
Comment 16 Mohit Kheterpal 2016-06-23 16:42:33 UTC
@Rolf, Could you please merge this fix in Cycle 7?

thanks
Comment 18 Mohit Kheterpal 2016-06-23 17:19:42 UTC
Thanks @Rolf

I have checked it with C7SR0 build of xamarin.ios-9.8.1.4_3cf8aaed100a8437c823d68402c2830e9625dda2 and observed that this issue has been fixed.
 
and its related card is in released Column : https://trello.com/c/QNf8E6uz/19-xi-xm-bug-41319-initwithcoder-has-been-explicitly-marked-unavailable

Thanks
Comment 19 Rolf Bjarne Kvinge [MSFT] 2016-07-14 14:32:36 UTC
*** Bug 42555 has been marked as a duplicate of this bug. ***
Comment 20 darshana.bhurewar 2016-07-15 06:45:38 UTC
I have tried removing `[Export("initWithCoder:")]` from the C# code.However, getting the same error again. Could you please tell me solution to resolve it. I am not able to build project at all.
Comment 21 Rolf Bjarne Kvinge [MSFT] 2016-07-15 09:33:36 UTC
@Darshana, please file a new bug and attach both the build log and the registrar.m file the error message mentions and I'll have a look.