public object CreateInstance(string assemblyPath, string typeName, string[] addins, IList <string> userAssemblyPaths = null) { lock (this) { references++; if (processHost == null) { Start(userAssemblyPaths); } } if (!runningEvent.WaitOne(15000, false)) { references--; throw new ApplicationException("Couldn't create a remote process."); } try { // Before creating the instance, load the add-ins on which it depends if (addins != null && addins.Length > 0) { processHost.LoadAddins(addins); } RemotingService.RegisterAssemblyForSimpleResolve(Path.GetFileNameWithoutExtension(assemblyPath)); object obj = processHost.CreateInstance(assemblyPath, typeName); RemotingService.RegisterMethodCallback(obj, "Dispose", RemoteProcessObjectDisposing, null); RemotingService.RegisterMethodCallback(obj, "Shutdown", RemoteProcessObjectShuttingDown, null); remoteObjects.Add(obj); Counters.ExternalObjects++; return(obj); } catch { ReleaseInstance(null); throw; } }