CLR Profiling API: Is it possible to read an object method paremeter and recreate it in C# ? RRS feed

  • Question

  • Hey,

    first of all excuse me if this is the wrong forum for that topic but i have not found one thats more suitable.

    I'm experimenting with the .NET CLR Profiling API. Let's assume there is a C# method with an object as parameter. So when the CLR calls EnterFunction3WithInfo for that method, would it be possible, to read the data for that parameter form the memory, transfer it with a named pipe (or other IPC mechanisms) to another C# application and "recreate" the object from that data there?

    I do not believe that this is possible, but I'm not an expert and would like to be sure before I give up that idea. :>

    Wednesday, May 24, 2017 1:25 PM

All replies

  • I believe it's technically possible to a limited degree, but is almost certainly not practical.

    Some of the problems that would arise include:

    • Ensuring both ends of the IPC are using the same version of all the assemblies involved (in case the fields changed).
    • What if the object contains a pointer sized field (IntPtr, UIntPtr, void*, etc) and is copied from a 64-bit process to a 32-bit process?
    • What if the source object contains a native resource reference? (virtual address, handle, etc)
    • What if the object forms part of a cyclic object graph?
    • What if the object is passed more than once? (do you pass some sort of identifier referencing the previous object? or re-copy the object graph? what if the object graph changed?)
    • What if you encounter a hash table where the type used as the key is a reference type that does not override GetHashCode?

    It might be 'ok' if you only want to copy a few specific object types of very limited complexity, but in such cases I would suggest you just copy the specific values you want and forget about recreating it.

    Wednesday, May 24, 2017 2:21 PM