Currently our runtime will try its best to make sure there's only a single managed instance for each native handle, and this is assumed in several places in the code base.
Unfortunately, we break this assumption ourselves in a couple of places:
We might have to add complete support for having multiple managed instances for the same native handle.
This would probably mean we'd have to make our IntPtr->INativeObject dictionary an IntPtr->List<INativeObject> dictionary instead. There could be one "main" mapping (whose managed type is determined by the runtime type of the native object, and returned when the caller doesn't know the managed type it wants - Runtime.GetNSObject), and then a list of other instances where the managed type is of a particular type.
Currently our runtime will try its best to make sure there's only a single managed instance for each native handle, and this is assumed in several places in the code base.
Unfortunately, we break this assumption ourselves in a couple of places:
We might have to add complete support for having multiple managed instances for the same native handle.
This would probably mean we'd have to make our IntPtr->INativeObject dictionary an IntPtr->List<INativeObject> dictionary instead. There could be one "main" mapping (whose managed type is determined by the runtime type of the native object, and returned when the caller doesn't know the managed type it wants - Runtime.GetNSObject), and then a list of other instances where the managed type is of a particular type.