I am trying to construct a managed object onto unmanaged memory allocated from Marshal.AllocHGlobal(). Currently, when I try to invoke the constructor delegate from reflection data, I get an exception that the object is the wrong type. I believe that if I could get a vftable pointer to the object and copy it over to the memory allocation, I could fool the language into invoking the constructor, but just getting a pointer to a static instance of the object is complicated already, and I don’t know if the vftable pointer is in the first 8 bytes let alone if I could even copy it. Is there some other way to do this without all of this crap?
Also, I know this is not supported; I do not want to see comments saying such.
New contributor