Skip to content

SIGABRT because constructor of subclassed class cannot be found #19076

Closed
@tipa

Description

@tipa

I am starting to see a new type of crash, which happens exclusively on iOS 17

Steps to Reproduce

sealed class HeaderTextField : UITextField
{
    public const int TOP_PADDING = 6;
    public const int SIDE_PADDING = 12;

    public override CGRect TextRect(CGRect forBounds)
    {
        var rect = base.EditingRect(forBounds);
        rect.X += SIDE_PADDING;
        rect.Y += TOP_PADDING;
        rect.Width -= SIDE_PADDING * 2;
        return rect;
    }

    public override CGRect EditingRect(CGRect forBounds)
    {
        var rect = base.EditingRect(forBounds);
        rect.X += SIDE_PADDING;
        rect.Y += TOP_PADDING;
        rect.Width -= SIDE_PADDING * 2;
        return rect;
    }

    public override CGRect ClearButtonRect(CGRect forBounds)
    {
        var rect = base.ClearButtonRect(forBounds);
        rect.X -= SIDE_PADDING;
        rect.Y += TOP_PADDING;
        return rect;
    }
}
myUIView.AddSubview(headerField = new HeaderTextField // headerField is a field in my view controller instance
{
     TranslatesAutoresizingMaskIntoConstraints = false,
     Text = "heading",
    ...
});

headerField.EditingChanged += HeaderField_EditingChanged;
headerField.Delegate = this;

Expected Behavior

No crash

Actual Behavior

Occasional crashes (reported via AppCenter)

SIGABRT: Failed to marshal the Objective-C object 0x108471400 (type: XYZ_HeaderTextField). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'XYZ.HeaderTextField' does not have a constructor that takes one NativeHandle argument).

ObjCRuntime.Runtime.MissingCtor(IntPtr , IntPtr , Type , MissingCtorResolution )
ObjCRuntime.Runtime.ConstructNSObject[NSObject](IntPtr , Type , MissingCtorResolution )
ObjCRuntime.Runtime.ConstructNSObject(IntPtr , IntPtr , MissingCtorResolution )
ObjCRuntime.Runtime.GetNSObject(IntPtr , MissingCtorResolution , Boolean )
ObjCRuntime.Runtime.GetNSObject(IntPtr )
ObjCRuntime.Runtime.InvokeConformsToProtocol(IntPtr , IntPtr )
ObjCRuntime.Runtime.invoke_conforms_to_protocol(IntPtr , IntPtr , IntPtr* )
UIKit.UIApplication.UIApplicationMain(Int32 , String[] , IntPtr , IntPtr )
UIKit.UIApplication.Main(String[] , Type , Type )
XYZ.Application.Main(String[] )

Looks like perhaps the instance was garbage collected and is then tried to be "activated" again? I think supplying a constructor as suggested in the error message would not really be a fix, but more of a workaround?

Environment

Version information
Visual Studio Community 2022 for Mac
Version 17.6.4 (build 472)
Installation UUID: cc844e24-b05c-438c-a679-a56e8eb93f62

Runtime
.NET 7.0.3 (64-bit)
Architecture: Arm64
Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2

Roslyn (Language Service)
4.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa

NuGet
Version: 6.4.0.117

.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/7.0.401/Sdks
SDK Versions:
	7.0.401
	6.0.414
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	7.0.11
	6.0.22

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

Updater
Version: 11

Apple Developer Tools
Xcode: 15.0 22265
Build: 15A240d

Xamarin.Mac
Version: 9.3.0.6 Visual Studio Community
Hash: 97731c92c
Branch: xcode14.3
Build date: 2023-04-11 22:38:35-0400

Xamarin.iOS
Version: 16.4.0.6 Visual Studio Community
Hash: 97731c92c
Branch: xcode14.3
Build date: 2023-04-11 22:38:36-0400

Xamarin Designer
Version: 17.6.3.9
Hash: 2648399ae8
Branch: remotes/origin/d17-6
Build date: 2023-09-07 02:05:20 UTC

Xamarin.Android
Not Installed

Microsoft Build of OpenJDK
Java SDK: Not Found

Eclipse Temurin JDK
Java SDK: Not Found

Android SDK Manager
Version: 17.6.0.50
Hash: a715dca
Branch: HEAD
Build date: 2023-09-07 02:05:26 UTC

Android Device Manager
Version: 0.0.0.1309
Hash: 06e3e77
Branch: HEAD
Build date: 2023-09-07 02:05:26 UTC

Build Information
Release ID: 1706040472
Git revision: 0b8c2cb9f01ef14a2b07ff4ea047268c8756fee6
Build date: 2023-09-07 02:03:50+00
Build branch: release-17.6
Build lane: release-17.6

Operating System
Mac OS X 13.5.2
Darwin 22.6.0 Darwin Kernel Version 22.6.0
    Wed Jul  5 22:22:52 PDT 2023
    root:xnu-8796.141.3~6/RELEASE_ARM64_T8103 arm64


Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions