Bug 34609 - MonoMac.Registrar.SharedStatic.IsNativeObject NotSupportedException at Mono.Cecil.TypeReference.Resolve
Summary: MonoMac.Registrar.SharedStatic.IsNativeObject NotSupportedException at Mono.C...
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: XI 9.2
Hardware: PC Mac OS
: Normal normal
Target Milestone: C6SR1
Assignee: Sebastien Pouliot
URL:
: 35371 ()
Depends on:
Blocks:
 
Reported: 2015-10-06 17:38 UTC by Frank A. Krueger
Modified: 2015-12-16 18:53 UTC (History)
6 users (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:
VERIFIED FIXED

Description Frank A. Krueger 2015-10-06 17:38:57 UTC
The following code works fine. But if you uncomment the lines, it fails to compile.


		async Task StartRecordingAsync ()
		{
			var recorder = RPScreenRecorder.SharedRecorder;

			await recorder.StartRecordingAsync (microphoneEnabled: true);
		}

		async Task StopRecordingAsync ()
		{
			var recorder = RPScreenRecorder.SharedRecorder;

			var previewController = await recorder.StopRecordingAsync ();

//			previewController.PreviewControllerDelegate = new PreviewDelegate ();

			await PresentViewControllerAsync (previewController, true);
		}

//		class PreviewDelegate : RPPreviewViewControllerDelegate
//		{
//			public override void DidFinish (RPPreviewViewController previewController)
//			{
//				previewController.DismissViewController (true, null);
//			}
//		}




		Xamarin.iOS 9.2.0 Priority Edition using framework: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk
MTOUCH: error MT4116: Could not register the assembly 'New9': System.NotSupportedException: Specified method is not supported.
		   at Mono.Cecil.TypeReference.Resolve () in <filename unknown>:line 0
		   at MonoMac.Registrar.SharedStatic.IsNativeObject (Mono.Cecil.TypeReference tr) in <filename unknown>:line 0
		   at MonoMac.Registrar.StaticRegistrar.IsINativeObject (Mono.Cecil.TypeReference tr) in <filename unknown>:line 0
		   at MonoMac.Registrar.Registrar.ToSignature (Mono.Cecil.TypeReference type, MonoMac.Registrar.ObjCMember member, System.Boolean& success, Boolean forProperty) in <filename unknown>:line 0
		   at MonoMac.Registrar.Registrar.ComputeSignature (Mono.Cecil.TypeReference DeclaringType, Mono.Cecil.MethodDefinition Method, MonoMac.Registrar.ObjCMember member, Boolean isCategoryInstance) in <filename unknown>:line 0
		   at MonoMac.Registrar.Registrar+ObjCMethod.ComputeSignature () in <filename unknown>:line 0
		   at MonoMac.Registrar.Registrar+ObjCMethod.ValidateSignature (System.Collections.Generic.List`1& exceptions) in <filename unknown>:line 0
		   at MonoMac.Registrar.Registrar+ObjCType.Add (MonoMac.Registrar.ObjCMethod method, System.Collections.Generic.List`1& exceptions) in <filename unknown>:line 0
		   at MonoMac.Registrar.Registrar.RegisterTypeUnsafe (Mono.Cecil.TypeReference type, System.Collections.Generic.List`1& exceptions) in <filename unknown>:line 0
		   at MonoMac.Registrar.Registrar.GetProtocols (MonoMac.Registrar.ObjCType type, System.Collections.Generic.List`1& exceptions) in <filename unknown>:line 0
		   at MonoMac.Registrar.Registrar.RegisterTypeUnsafe (Mono.Cecil.TypeReference type, System.Collections.Generic.List`1& exceptions) in <filename unknown>:line 0
		   at MonoMac.Registrar.Registrar.RegisterTypeUnsafe (Mono.Cecil.TypeReference type, System.Collections.Generic.List`1& exceptions) in <filename unknown>:line 0
		   at MonoMac.Registrar.Registrar.RegisterAssembly (Mono.Cecil.AssemblyDefinition assembly) in <filename unknown>:line 0
	Task "MTouch" execution -- FAILED
	Done building target "_CompileToNative" in project "/Users/fak/Dropbox/Documents/Presentations/20151006 Seattle Mobile iOS 9/New9/New9.csproj".-- FAILED


=== Xamarin Studio ===

Version 5.10 (build 811)
Installation UUID: e51e2705-c52a-4ae8-aa07-c481d6ab8a7a
Runtime:
	Mono 4.2.1 (explicit/804ddbc)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010060

=== Xamarin.Profiler ===

Version: 0.22.0.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 7.0 (8223)
Build 7A218

=== Xamarin.iOS ===

Version: 9.2.0.84 (Enterprise Edition)
Hash: b5396c2
Branch: master
Build date: 2015-09-30 15:22:15-0400

=== Xamarin.Android ===

Version: 6.0.0.8 (Enterprise Edition)
Android SDK: /Users/fak/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)

SDK Tools Version: 23.0.5
SDK Platform Tools Version: 21
SDK Build Tools Version: 20

Java SDK: /usr
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

=== Xamarin Android Player ===

Version: 0.3.7
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.4.0.79 (Enterprise Edition)

=== Build Information ===

Release ID: 510000811
Git revision: 34cd31ea72536afab530c14d9220b286075e83cd
Build date: 2015-09-30 10:40:37-04
Xamarin addins: 8e6fccfc0c19a7e0b7b11be925f09751d827eb5c
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.10.5
Darwin lepton.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 1 Rodrigo Kumpera 2015-10-06 18:04:13 UTC
Hi Sebastien,

This looks like a Cecil / registrar issue.
Comment 2 Sebastien Pouliot 2015-10-06 21:44:54 UTC
@Rolf, it seems the new generic types are not handled in

> MonoMac.Registrar.SharedStatic.IsNativeObject

It fails when it tries to resolve API like:

> Foundation.NSSet`1<Foundation.NSString> : Mono.Cecil.GenericInstanceType
Comment 3 Rolf Bjarne Kvinge [MSFT] 2015-10-07 11:19:56 UTC
@Sebastien, the static registrar fails because the linker removed Foundation.NSSet`1.

My guess is that the linker doesn't completely understand arrays of types inside attributes:

> [ProtocolMember (..., ParameterType = new Type [] { typeof (ReplayKit.RPPreviewViewController), typeof (NSSet<NSString>) }, ...)]

that said, I'm not sure the linker should remove these types (since the ProtocolMember attributes can be removed once the static registrar has run), but at this point we end up playing ping-ping with the assemblies between the linker and the static registrar.

In any case there's a bug in the linker, because it shouldn't remove types used in attributes like this (removing them from ProtocolMember would be a later optimization/special-case).

@Frank, a simple workaround is to make sure NSSet`1 isn't linked away:

>    Console.WriteLine (new NSSet<NSString> ()); // somewhere in your code.

Downgrading importance since there's a trivial workaround.
Comment 4 Sebastien Pouliot 2015-10-07 13:38:37 UTC
Did I ever mention I hate custom attribute encoding ?

The good news is that it explains why tests/samples did not catch it. Any (unrelated) API using the NSSet<T> type would solve/hide the issue.

@Rolf there should not be a ping-pong issue. The linker's mark/sweep steps are done separately (and before) than the attribute removal step. As long as the static registrar is moved in between those steps it should be fine (I know, famous last words ;-)
Comment 5 Rolf Bjarne Kvinge [MSFT] 2015-10-07 14:14:22 UTC
(In reply to comment #4)

> @Rolf there should not be a ping-pong issue. The linker's mark/sweep steps are
> done separately (and before) than the attribute removal step. As long as the
> static registrar is moved in between those steps it should be fine (I know,
> famous last words ;-)

@Sebastien, not quite, if you remove something (in this case not the attribute itself, but a type used in the attribute) in mark/sweep then it won't be available for the static registrar in the next step (and you're back to the exception this bug report shows). Obviously not unfixable, but when you start looking deeper at the details it gets muddier that what it seems at first sight :) I'm thinking we need to store information in cecil's annotations the static registrar needs (but that's out of scope for this bug).
Comment 6 Sebastien Pouliot 2015-10-07 21:21:36 UTC
fixed in maccore/master 2fb8866b34ee507c5457bb77af32dedb01d20796

related commits:
mono/mono-4.2.0-thawed 0b5220934ee70ccdc1cb15b2816f94d00cb95267
mono/master 778adf07692178a56fffa34f4b50df13a6074e6e

Candidate for C6 SR1 -
https://trello.com/c/CQ4r8Kkn/28-xi-xm-xa-linker-fix-for-generics-usage-in-custom-attributes
Comment 7 Rolf Bjarne Kvinge [MSFT] 2015-11-03 06:57:42 UTC
*** Bug 35371 has been marked as a duplicate of this bug. ***
Comment 8 Rajneesh Kumar 2015-12-04 19:11:59 UTC
I have checked this issue with the following master build:
monotouch-9.3.2.535_3b70c8e6812016ffcf4feaeb3d04fe30b5db11f9

I observed that I am able to build and deploy (on device), the attached test sample successfully without any crash.

Screencast: http://www.screencast.com/t/w6z5kEygAcYQ

Environment Info: https://gist.github.com/Abhishekk360/32d93f7c3191e8b5a614

I will Re-Verify this issue when the fix will merge in Release branch.

Thanks..!
Comment 9 Rajneesh Kumar 2015-12-16 18:53:14 UTC
I have checked this issue with the following C6SR1 build:
monotouch-9.4.1.8_f146d47db0476e3519dc6e8229af74a4e867f386

I observed that I am able to build and deploy device/simulator, the attached test sample (Bug 35371) successfully without any crash.

Screencast: http://www.screencast.com/t/ih8KVwPrxQ1I

This issue has been fixed hence I am closing this issue.

Thanks..!