C
C#3y ago
Thinker

What's the purpose of MarshalByRefObject?

A couple of classes in the standard library inherit from MarshalByRefObject, but what is the purpose of it?
3 Replies
Thinker
ThinkerOP3y ago
My assumption is that it's some remnant from the COM days or something
canton7
canton73y ago
The docs give a nice overview: https://learn.microsoft.com/en-us/dotnet/api/system.marshalbyrefobject?view=net-7.0#remarks . It's for appdomains: normally if you make a call to another AppDomain, all of the method parameters and the return type get marshalled by value. You can marshal by reference instead by inheriting from MarshalByRefObject. That lets you pass an object across an AppDomain boundary, and any time the state of that object is changed in one AppDomain, that change is reflected back in the other AppDomain
MarshalByRefObject Class (System)
Enables access to objects across application domain boundaries in applications that support remoting.
Thinker
ThinkerOP3y ago
huh, right

Did you find this page helpful?