diff --git a/src/ObjCRuntime/DynamicRegistrar.cs b/src/ObjCRuntime/DynamicRegistrar.cs index de90b2e504..5fce1f74c0 100644 --- a/src/ObjCRuntime/DynamicRegistrar.cs +++ b/src/ObjCRuntime/DynamicRegistrar.cs @@ -934,7 +934,9 @@ namespace Registrar { UnlockRegistrar (); } - throw ErrorHelper.CreateError (4143, "The ObjectiveC class '{0}' could not be registered, it does not seem to derive from any known ObjectiveC class (including NSObject).", Marshal.PtrToStringAuto (Class.class_getName (original_class))); + if (throw_on_error) + throw ErrorHelper.CreateError (4143, "The ObjectiveC class '{0}' could not be registered, it does not seem to derive from any known ObjectiveC class (including NSObject).", Marshal.PtrToStringAuto (Class.class_getName (original_class))); + return null; } bool RegisterMethod (ObjCMethod method) diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index 1f8268d0ad..bc5c2e4a80 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -1331,7 +1331,7 @@ namespace ObjCRuntime { return ConstructNSObject (ptr, target_type, MissingCtorResolution.ThrowConstructor1NotFound); } - static Type LookupINativeObjectImplementation (IntPtr ptr, Type target_type, Type implementation = null) + static Type LookupINativeObjectImplementation (IntPtr ptr, Type target_type, Type implementation = null, bool forced_type = false) { if (!typeof (NSObject).IsAssignableFrom (target_type)) { // If we're not expecting an NSObject, we can't do a dynamic lookup of the type of ptr, @@ -1348,7 +1348,8 @@ namespace ObjCRuntime { if (implementation == null) implementation = target_type; } else { - var runtime_type = Class.Lookup (p); + // only throw if we're not forcing the type we want to expose + var runtime_type = Class.Lookup (p, throw_on_error: !forced_type); // Check if the runtime type can actually be used. if (target_type.IsAssignableFrom (runtime_type)) { implementation = runtime_type; @@ -1450,7 +1451,7 @@ namespace ObjCRuntime { } // Lookup the ObjC type of the ptr and see if we can use it. - var implementation = LookupINativeObjectImplementation (ptr, typeof (T)); + var implementation = LookupINativeObjectImplementation (ptr, typeof (T), forced_type: forced_type); if (implementation.IsSubclassOf (typeof (NSObject))) { if (o != null && !forced_type) { diff --git a/src/mediaplayer.cs b/src/mediaplayer.cs index 8bd42e443e..f7b1546380 100644 --- a/src/mediaplayer.cs +++ b/src/mediaplayer.cs @@ -1177,6 +1177,7 @@ namespace MediaPlayer { [Export ("indexOfNowPlayingItem")] nuint IndexOfNowPlayingItem { get; } + [ForcedType] [Export ("nowPlayingItem", ArgumentSemantic.Copy), NullAllowed] MPMediaItem NowPlayingItem { get; set; }