Skip to content

Improve diagnostics when objects are disposed too early #22975

@rolfbjarne

Description

@rolfbjarne

When a managed wrapper object is Disposed, and then native code later re-exposes the same native handle to managed code, this happens:

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

I wonder if we could improve diagnostics for this scenario by:

  • Setting a flag on in the the NSObject.flags field to indicate a disposed object.
  • Keep any disposed objects in the Runtime dictionary of intptr->wrapper mappings, but return a special lookup failure if the object is there, but disposed.
  • Show a different error message in this case.
  • We could also make it a build-time option to capture a stack trace when Dispose is called too early, and show that stack trace later on in the error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureA feature to be implemented

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions