#2867 added caching for type metadata. Type metadata pointers will come from two sources, ISwiftObject.GetTypeMetadata() and internal storage (for primitives). It might happen that ISwiftObject.GetTypeMetadata() returns a IntPtr.Zero (e.g. current implementation of AnyType). This is not a valid TypeMetadata and we should fail and produce a meaningful error on receiving it. Otherwise the program might fail without any meaningful message on pinvoke call.
In #2958 I added safeguards around static accessors to fail when TypeMetadata is invalid, however caching happens before the check. On following reads of the feral TypeMetadata the incorrect value is returned silently.
We should refactor the caching mechanism to ensure that only valid values are cached.