This makes diagnosing what happens much easier in some cases.
Exhibit A, pre fix:
*** Terminating app due to uncaught exception 'ObjCRuntime.RuntimeException', reason: 'Failed to lookup the required marshalling information.
Additional information:
Selector: conformsToProtocol:
Type: ViewController
Exhibit B, post fix:
*** Terminating app due to uncaught exception 'ObjCRuntime.RuntimeException', reason: 'Failed to lookup the required marshalling information.
Additional information:
Selector: conformsToProtocol:
Type: ViewController
(ObjCRuntime.RuntimeException)
Failed to get the 'this' instance in a method call to templ.ViewController.InvokeConformsToProtocol. (ObjCRuntime.RuntimeException)
at Registrar.DynamicRegistrar.GetMethodDescriptionAndObject(Type type, IntPtr selector, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc)
at ObjCRuntime.Runtime.GetMethodAndObjectForSelector(IntPtr klass, IntPtr sel, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc)
at ObjCRuntime.Runtime.get_method_and_object_for_selector(IntPtr cls, IntPtr sel, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc, IntPtr& exception_gchandle)
Failed to marshal the Objective-C object 0x7f813fd2f470 (type: ViewController). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'templ.ViewController' does not have a constructor that takes one NativeHandle argument). (ObjCRuntime.RuntimeException)
at ObjCRuntime.Runtime.MissingCtor(IntPtr ptr, IntPtr klass, Type type, MissingCtorResolution resolution)
at ObjCRuntime.Runtime.ConstructNSObject[T](IntPtr ptr, Type type, MissingCtorResolution missingCtorResolution)
at ObjCRuntime.Runtime.ConstructNSObject(IntPtr ptr, IntPtr klass, MissingCtorResolution missingCtorResolution)
at ObjCRuntime.Runtime.GetNSObject(IntPtr ptr, MissingCtorResolution missingCtorResolution, Boolean evenInFinalizerQueue)
at Registrar.DynamicRegistrar.GetMethodDescriptionAndObject(Type type, IntPtr selector, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc)
It does exactly what you'd think it does: nothing helpful at all.
Make sure to use a GCHandle that's alive instead.
Output before fix:
Xamarin.Mac: Processing managed exception for exception marshalling (mode: 2):
Failed to print exception: System.NullReferenceException: Object reference not set to an instance of an object.
at ObjCRuntime.Runtime.PrintException(Exception exc, Boolean isInnerException, StringBuilder sb)
at ObjCRuntime.Runtime.PrintAllExceptions(IntPtr exception_gchandle)
Output after fix:
Xamarin.Mac: Processing managed exception for exception marshalling (mode: 2):
Failed to lookup the required marshalling information.
Additional information:
Selector: conformsToProtocol:
Type: ViewController
(ObjCRuntime.RuntimeException)
Failed to get the 'this' instance in a method call to templ.ViewController.InvokeConformsToProtocol. (ObjCRuntime.RuntimeException)
at Registrar.DynamicRegistrar.GetMethodDescriptionAndObject(Type type, IntPtr selector, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc)
at ObjCRuntime.Runtime.GetMethodAndObjectForSelector(IntPtr klass, IntPtr sel, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc)
at ObjCRuntime.Runtime.get_method_and_object_for_selector(IntPtr cls, IntPtr sel, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc, IntPtr& exception_gchandle)
Failed to marshal the Objective-C object 0x7f89e6c2a2a0 (type: ViewController). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'templ.ViewController' does not have a constructor that takes one NativeHandle argument). (ObjCRuntime.RuntimeException)
at ObjCRuntime.Runtime.MissingCtor(IntPtr ptr, IntPtr klass, Type type, MissingCtorResolution resolution)
at ObjCRuntime.Runtime.ConstructNSObject[T](IntPtr ptr, Type type, MissingCtorResolution missingCtorResolution)
at ObjCRuntime.Runtime.ConstructNSObject(IntPtr ptr, IntPtr klass, MissingCtorResolution missingCtorResolution)
at ObjCRuntime.Runtime.GetNSObject(IntPtr ptr, MissingCtorResolution missingCtorResolution, Boolean evenInFinalizerQueue)
at Registrar.DynamicRegistrar.GetMethodDescriptionAndObject(Type type, IntPtr selector, Boolean is_static, IntPtr obj, IntPtr& mthis, IntPtr desc)
This speeds up builds significantly when the linker is disabled.
Test case: building tests/dotnet/MySimpleApp for macOS.
* Before: 37s
* After: 9s
* Difference: 26s (4x faster)
Test case: run the .NET tests
* Before: 2h55
* After: 1h43
* Difference: 1h12 (1.7x faster)
Contributes towards https://github.com/xamarin/xamarin-macios/issues/10251.
Ref: https://github.com/dotnet/linker/issues/2089
* [coreimage] Modernize CIFilter
* Use faster `CFString` API (over the slower `NSString` variants)
* Rework internal API to use handles whenever possible
* Better use (and dispose) of `NSNumber`
* Use `ThrowHelper` to throw common exceptions
* Add related binding changes
Output before fix:
Xamarin.Mac: Processing managed exception for exception marshalling (mode: 2):
Failed to print exception: System.NullReferenceException: Object reference not set to an instance of an object.
at ObjCRuntime.Runtime.PrintException(Exception exc, Boolean isInnerException, StringBuilder sb)
at ObjCRuntime.Runtime.PrintAllExceptions(IntPtr exception_gchandle)
Output after fix:
Xamarin.Mac: Processing managed exception for exception marshalling (mode: 2):
Unable to print exception handle 0x102ca12b8: null exception
while not much more informative, it's at least not throwing a NullReferenceException that seems unexpected.
* A lot of obsolete/deprecated removal.
* Remove the NSDraggingInfo model, which required numerous other changes.
* Remove the NSPasteboardReading/NSPasteboardWriting models, which required more
numerous changes.
* Update the tests accordingly.
* Use 'ObjCException' instead of 'MonoTouchException' as the managed exception
type wrapping an NSException for all platforms in .NET (that was already the
case for macOS, so no change there).
* Make the ObjCException class behave like the MonoTouchException class does.
* Move the ObjCException type to the ObjCRuntime namespace in .NET.
Fixes https://github.com/xamarin/xamarin-macios/issues/13855.
Co-authored-by: TJ Lambert <50846373+tj-devel709@users.noreply.github.com>
Also make the (NativeHandle) constructor protected instead of public, to make
it clearer that it's not for public consumption.
And modify the template tests to execute the template if we can.
Fixes https://github.com/xamarin/xamarin-macios/issues/13979.
This turned out a bit complex, because numerous ModelIO APIs were initially bound
with wrong matrix types, and had to be rebound later (our matrix type was transposed
with regards to the native matrix type). The new versions often had to use worse
names, so that's being fixed now. This means that numerous tests had to be updated,
because the original API now returns non-transposed matrices.
* [CHIP] Updates for Xcode13.2 beta 1
* Update based on feedback
* Update based on feedback and intro test failure
* Update xtro .todo files
* Fix some breaking API changes
* Delete silly typos
Fixes:
ObjCRuntime/Runtime.cs(64,15): warning CS0649: Field 'Runtime.MTRegistrationMap.protocol_wrapper_count' is never assigned to, and will always have its default value 0
ObjCRuntime/Runtime.cs(111,18): warning CS0649: Field 'Runtime.Trampolines.ctor_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(58,33): warning CS0649: Field 'Runtime.MTRegistrationMap.protocol_wrapper_map' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(63,15): warning CS0649: Field 'Runtime.MTRegistrationMap.skipped_map_count' is never assigned to, and will always have its default value 0
CoreText/CTStringAttributes.cs(104,37): warning CS0649: Field 'CTStringAttributeKey.WritingDirection' is never assigned to, and will always have its default value null
ObjCRuntime/Runtime.cs(125,18): warning CS0649: Field 'Runtime.Trampolines.get_flags_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(121,18): warning CS0649: Field 'Runtime.Trampolines.copy_with_zone_2' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(61,15): warning CS0649: Field 'Runtime.MTRegistrationMap.map_count' is never assigned to, and will always have its default value 0
ObjCRuntime/Runtime.cs(117,18): warning CS0649: Field 'Runtime.Trampolines.long_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(56,18): warning CS0649: Field 'Runtime.MTRegistrationMap.full_token_references' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(126,18): warning CS0649: Field 'Runtime.Trampolines.set_flags_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(104,18): warning CS0649: Field 'Runtime.Trampolines.tramp' is never assigned to, and will always have its default value
CoreText/CTStringAttributes.cs(101,37): warning CS0649: Field 'CTStringAttributeKey.BaselineInfo' is never assigned to, and will always have its default value null
ObjCRuntime/Runtime.cs(60,15): warning CS0649: Field 'Runtime.MTRegistrationMap.assembly_count' is never assigned to, and will always have its default value 0
ObjCRuntime/Runtime.cs(116,18): warning CS0649: Field 'Runtime.Trampolines.x86_double_abi_static_stret_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(106,18): warning CS0649: Field 'Runtime.Trampolines.fpret_single_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(105,18): warning CS0649: Field 'Runtime.Trampolines.stret_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(113,18): warning CS0649: Field 'Runtime.Trampolines.static_fpret_single_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(120,18): warning CS0649: Field 'Runtime.Trampolines.copy_with_zone_1' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(62,15): warning CS0649: Field 'Runtime.MTRegistrationMap.full_token_reference_count' is never assigned to, and will always have its default value 0
ObjCRuntime/Runtime.cs(118,18): warning CS0649: Field 'Runtime.Trampolines.static_long_tramp' is never assigned to, and will always have its default value
CoreText/CTStringAttributes.cs(102,37): warning CS0649: Field 'CTStringAttributeKey.BaselineReferenceInfo' is never assigned to, and will always have its default value null
ObjCRuntime/Runtime.cs(59,25): warning CS0649: Field 'Runtime.MTRegistrationMap.protocol_map' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(108,18): warning CS0649: Field 'Runtime.Trampolines.release_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(55,23): warning CS0649: Field 'Runtime.MTRegistrationMap.map' is never assigned to, and will always have its default value
CoreText/CTStringAttributes.cs(100,37): warning CS0649: Field 'CTStringAttributeKey.BaselineClass' is never assigned to, and will always have its default value null
ObjCRuntime/Runtime.cs(123,18): warning CS0649: Field 'Runtime.Trampolines.get_gchandle_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(57,30): warning CS0649: Field 'Runtime.MTRegistrationMap.skipped_map' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(65,15): warning CS0649: Field 'Runtime.MTRegistrationMap.protocol_count' is never assigned to, and will always have its default value 0
ObjCRuntime/Runtime.cs(124,18): warning CS0649: Field 'Runtime.Trampolines.set_gchandle_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(115,18): warning CS0649: Field 'Runtime.Trampolines.static_stret_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(54,18): warning CS0649: Field 'Runtime.MTRegistrationMap.assembly' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(109,18): warning CS0649: Field 'Runtime.Trampolines.retain_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(114,18): warning CS0649: Field 'Runtime.Trampolines.static_fpret_double_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(107,18): warning CS0649: Field 'Runtime.Trampolines.fpret_double_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(110,18): warning CS0649: Field 'Runtime.Trampolines.static_tramp' is never assigned to, and will always have its default value
ObjCRuntime/Runtime.cs(112,18): warning CS0649: Field 'Runtime.Trampolines.x86_double_abi_stret_tramp' is never assigned to, and will always have its default value