Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

456
Views
Invoque MethodInfo con void* como parámetro

El problema

Hay un método interno que necesito invocar a través de la reflexión. Se parece a esto...

 internal void SetComponentDataRaw(Entity entity, int typeIndex, void* data, int size)

Obtener MethodInfo no es un problema, pero llamarlo sí lo es. Necesito pasarle un puntero de vacío, pero ese puntero de vacío NO se puede convertir en un objeto. Cuando encajo ese puntero, recibo un error más adelante que me dice que no puede desempaquetarlo correctamente.

 var SetComponentDataRawInfo = typeof(...).GetMethod("SetComponentDataRaw", ...); var entity = someEntityToPass; var cmp = new StructToPassToTheMethodAsAPointer(); // My first attempt, not possible to cast unsafe { var handle = GCHandle.Alloc(cmp, GCHandleType.Pinned); var adress = handle.AddrOfPinnedObject(); var ptr = adress.ToPointer(); var sizeOfComponent = UnsafeUtility.SizeOf(type); var parameters = new [] {entity, cmpType.TypeIndex, (object)ptr, sizeOfComponent}; // (object)ptr not possible SetComponentDataRawInfo.Invoke(em, parameters); handle.Free(); } // Second attempt unsafe { var handle = GCHandle.Alloc(cmp, GCHandleType.Pinned); var adress = handle.AddrOfPinnedObject(); var ptr = adress.ToPointer(); var sizeOfComponent = UnsafeUtility.SizeOf(type); var parameters = new [] {entity, cmpType.TypeIndex, Pointer.Box(ptr, typeof(void*)), sizeOfComponent}; SetComponentDataRawInfo.Invoke(em, parameters); handle.Free(); }

El segundo intento puede invocar el método... pero recibo la siguiente excepción: ArgumentException: Object of type 'System.Reflection.Pointer' cannot be converted to type 'System.Void*'.

La pregunta

¿Cómo invocamos un MethodInfo con un vacío puro* como parámetro? Me alegro de cualquier ayuda sobre este tema!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!