Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do reflection and remoting work internally?

I am curious to know how Reflection and Remoting in .net work internally. I also hear that .net can use remoting to communicate with applications written in other languages (such as Java). How does that work?

This is probably a large question so an answer that briefly touches upon each question is reasonable.

like image 347
Jeremy Edwards Avatar asked Feb 01 '26 08:02

Jeremy Edwards


1 Answers

Remoting works by intercepting calls to certain objects (MarshalByRefObject), and by performing an RPC call instead; essentially the object at the caller is just a lightweight proxy to the real object at the originating AppDomain/machine/etc. The arguments and results are transferred (again, taking MarshalByRefObject into account - otherwise by using BinaryFormatter to serialize the values).

Reflection is built deep into the core runtime, and provides access to the underlying type definitions. This is possibly in part because the IL underneath .NET languages is quite expressive in terms of the original code.

However, I am not personally aware of any way to talk via remoting to java. It may be possible, but the formats used are (AFAIK) proprietary. In general, such calls are more likely to take the form of SOA calls, such as web-services (on SOAP or POX), or other open standards such as messages serialized with JSON or "protocol buffers" (an open-source wire format with variants for both C# and java).

like image 168
Marc Gravell Avatar answered Feb 02 '26 20:02

Marc Gravell