fork download
  1. using System;
  2. using System.Reflection;
  3.  
  4. public class Worker : MarshalByRefObject
  5. {
  6. public void PrintDomain()
  7. {
  8. Console.WriteLine("Object is executing in AppDomain \"{0}\"",
  9. AppDomain.CurrentDomain.FriendlyName);
  10. }
  11. }
  12.  
  13. class Example
  14. {
  15. public static void Main()
  16. {
  17. // Create an ordinary instance in the current AppDomain
  18. Worker localWorker = new Worker();
  19. localWorker.PrintDomain();
  20.  
  21. // Create a new application domain, create an instance
  22. // of Worker in the application domain, and execute code
  23. // there.
  24. AppDomain ad = AppDomain.CreateDomain("New domain");
  25. Worker remoteWorker = (Worker) ad.CreateInstanceAndUnwrap(
  26. Assembly.GetExecutingAssembly().FullName,
  27. "Worker123");
  28. if (remoteWorker == null) {
  29. Console.WriteLine("Got null");
  30. return;
  31. }
  32. remoteWorker.PrintDomain();
  33. }
  34. }
Runtime error #stdin #stdout #stderr 0.38s 38928KB
stdin
Standard input is empty
stdout
Object is executing in AppDomain "prog.exe"
stderr
Unhandled Exception: System.TypeLoadException: Could not load type 'Worker123'.

Server stack trace: 
  at (wrapper managed-to-native) System.Reflection.Assembly:InternalGetType (System.Reflection.Assembly,System.Reflection.Module,string,bool,bool)
  at System.Reflection.Assembly.GetType (System.String name, Boolean throwOnError, Boolean ignoreCase) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.String assemblyName, System.String typeName, Boolean ignoreCase, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Security.Policy.Evidence securityInfo) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.String assemblyName, System.String typeName, System.Object[] activationAttributes) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.String assemblyName, System.String typeName) [0x00000] in <filename unknown>:0 
  at System.AppDomain.CreateInstance (System.String assemblyName, System.String typeName) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.AppDomain:CreateInstance (string,string)
  at System.AppDomain.CreateInstanceAndUnwrap (System.String assemblyName, System.String typeName) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.AppDomain:CreateInstanceAndUnwrap (string,string)
  at (wrapper xdomain-dispatch) System.AppDomain:CreateInstanceAndUnwrap (object,byte[]&,byte[]&,string,string)

Exception rethrown at [0]: 

  at (wrapper xdomain-invoke) System.AppDomain:CreateInstanceAndUnwrap (string,string)
  at (wrapper remoting-invoke-with-check) System.AppDomain:CreateInstanceAndUnwrap (string,string)
  at Example.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'Worker123'.

Server stack trace: 
  at (wrapper managed-to-native) System.Reflection.Assembly:InternalGetType (System.Reflection.Assembly,System.Reflection.Module,string,bool,bool)
  at System.Reflection.Assembly.GetType (System.String name, Boolean throwOnError, Boolean ignoreCase) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.String assemblyName, System.String typeName, Boolean ignoreCase, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Security.Policy.Evidence securityInfo) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.String assemblyName, System.String typeName, System.Object[] activationAttributes) [0x00000] in <filename unknown>:0 
  at System.Activator.CreateInstance (System.String assemblyName, System.String typeName) [0x00000] in <filename unknown>:0 
  at System.AppDomain.CreateInstance (System.String assemblyName, System.String typeName) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.AppDomain:CreateInstance (string,string)
  at System.AppDomain.CreateInstanceAndUnwrap (System.String assemblyName, System.String typeName) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.AppDomain:CreateInstanceAndUnwrap (string,string)
  at (wrapper xdomain-dispatch) System.AppDomain:CreateInstanceAndUnwrap (object,byte[]&,byte[]&,string,string)

Exception rethrown at [0]: 

  at (wrapper xdomain-invoke) System.AppDomain:CreateInstanceAndUnwrap (string,string)
  at (wrapper remoting-invoke-with-check) System.AppDomain:CreateInstanceAndUnwrap (string,string)
  at Example.Main () [0x00000] in <filename unknown>:0