private Task <int> ExecuteMain(DefaultHost host, string applicationName, string[] args) { Assembly assembly = null; try { assembly = host.GetEntryPoint(applicationName); } catch (FileNotFoundException ex) when(new AssemblyName(ex.FileName).Name == applicationName) { if (ex.InnerException is ICompilationException) { throw ex.InnerException; } ThrowEntryPointNotfoundException( host, applicationName, ex.InnerException); } if (assembly == null) { return(Task.FromResult(-1)); } return(EntryPointExecutor.Execute(assembly, args, host.ServiceProvider)); }
private Task <int> ExecuteMain(DefaultHost host, string applicationName, string[] args) { Assembly assembly = null; try { assembly = host.GetEntryPoint(applicationName); } // Compilation exceptions either throw FileNotFound or FileLoad exceptions and may change // from version to version. It's safest to catch both types of exceptions catch (Exception ex) when(ex is FileLoadException || ex is FileNotFoundException) { if (ex.InnerException is ICompilationException) { throw SuppressStackTrace(ex.InnerException); } ThrowEntryPointNotfoundException( host, applicationName, ex.InnerException); } if (assembly == null) { return(Task.FromResult(-1)); } return(EntryPointExecutor.Execute(assembly, args, host.ServiceProvider)); }
private static Task <int> ExecuteMain(DefaultHost host, string applicationName, string[] args) { Assembly assembly = null; try { assembly = host.GetEntryPoint(applicationName); } catch (Exception ex) { SuppressCompilationExceptions(ex); if (ex is FileLoadException || ex is FileNotFoundException) { ThrowEntryPointNotfoundException( host, applicationName, ex.InnerException); } throw; } if (assembly == null) { return(Task.FromResult(1)); } return(Task.Run(() => EntryPointExecutor.Execute(assembly, args, host.ServiceProvider)) .ContinueWith(t => { t.Exception?.Handle(e => { SuppressCompilationExceptions(e); return false; }); return t.Result; })); }