dotnet / dotnet/macios

Improve diagnostics when objects are disposed too early

Open
#22,975 0 comments 1 reaction 0 assignees View on GitHub
feature
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 12h
Merged PRs (30d)
123

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.