Subscribe

RSS Feed (xml)

Create a Type That Can't Cross Application Domain Boundaries

Sometimes, you may want to ensure that instances of a type can't transcend application domain boundaries. To create a nonremotable type, ensure that it isn't serializable and that it doesn't derive (directly or indirectly) from the MarshalByRefObject class. If you take these steps, you ensure that an object's state can never be accessed from outside the application domain in which the object was instantiated—such objects can't be used as arguments or return values in cross-application domain method calls.
Ensuring that a type isn't serializable is easy because a class doesn't inherit the ability to be serialized from its parent class. To ensure that a type isn't serializable, make sure it doesn't have  
System.SerializableAttribute
applied to the type declaration.
Ensuring that a class can't be passed by reference requires a little more attention. Many classes in the .NET class library derive directly or indirectly from MarshalByRefObject; you must be careful that you don't inadvertently derive your class from one of these. Commonly used base classes that derive from MarshalByRefObject include System.ComponentModel.Component, System.IO.Stream, System.IO.TextReader, System.IO.TextWriter, System.NET.WebRequest, and System.Net.WebResponse. (Check the .NET Framework SDK documentation for a list of classes derived from MarshalByRefObject.)

No comments:

Post a Comment

Archives

LocalsAdda.com-Variety In Web World

Fun Mail - Fun in the Mail