public int Run(string[] talkBackArgs, XRefArguments xRefArgs, CrossAppDomainCommunicator.MessageReceivedDelegate onMessageReceived = null)
        {
            // Create new application domain and run cross referencer
              var appDomain = AppDomain.CurrentDomain;

              var setupInformation = appDomain.SetupInformation;
              setupInformation.ApplicationBase = xRefArgs.AssemblyDirectory;

              if(!string.IsNullOrEmpty(xRefArgs.AppBaseDirectory))
              {
            setupInformation.ApplicationBase = xRefArgs.AppBaseDirectory;

            var appBaseDirectory = xRefArgs.AppBaseDirectory;
            if (!appBaseDirectory.EndsWith ("\\"))
              appBaseDirectory += "\\";

            if(xRefArgs.AssemblyDirectory.StartsWith(appBaseDirectory))
            {
              var relativeSearchPath = xRefArgs.AssemblyDirectory.Remove (0, appBaseDirectory.Length);
              if (!string.IsNullOrEmpty (relativeSearchPath))
              {
            setupInformation.PrivateBinPath = relativeSearchPath;
              }
            }
            else
            {
              throw new ArgumentException ("Input directory is not a sub directory of application base directory!");
            }
              }
              if (!string.IsNullOrEmpty (xRefArgs.AppConfigFile))
              {
            if (!File.Exists (xRefArgs.AppConfigFile))
              throw new ArgumentException (string.Format ("Supplied app-config file '{0}' does not exist.", xRefArgs.AppConfigFile));

            setupInformation.ConfigurationFile = xRefArgs.AppConfigFile;

            // The PrivateBinPath needs to be read manually from the config because for some reason it does not via automatic setup.
            var privateBinPath = GetPrivateBinPathFromConfig (xRefArgs.AppConfigFile);
            if (!string.IsNullOrEmpty (privateBinPath))
            {
              if (string.IsNullOrEmpty (setupInformation.PrivateBinPath))
            setupInformation.PrivateBinPath = privateBinPath;
              else
            setupInformation.PrivateBinPath = setupInformation.PrivateBinPath + ";" + privateBinPath;
            }
              }

              var newAppDomain = AppDomain.CreateDomain ("XRefAppDomain", appDomain.Evidence, setupInformation, new PermissionSet(PermissionState.Unrestricted));
              var crossAppDomainCommunicatorType = typeof (CrossAppDomainCommunicator);
              var proxy = (CrossAppDomainCommunicator) newAppDomain.CreateInstanceFromAndUnwrap (crossAppDomainCommunicatorType.Assembly.Location, crossAppDomainCommunicatorType.FullName);
              if(onMessageReceived != null)
            proxy.SetMessageReceivedDelegate(new MessageReceivedDelegateWrapper(onMessageReceived).OnMessageReceived);
              return proxy.Run (talkBackArgs, xRefArgs);
        }
 public MessageReceivedDelegateWrapper(CrossAppDomainCommunicator.MessageReceivedDelegate onMessageReceived)
 {
     _onMessageReceived = onMessageReceived;
 }