In my C# project I have the following
private static JScriptEngine JSE = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging | WindowsScriptEngineFlags.EnableJITDebugging);
...
JSE.AddHostObject("CSHost", new HostFunctions());
JSE.AddHostObject("CSExtendedHost", new ExtendedHostFunctions());
JSE.AddHostObject("CS", new HostTypeCollection("mscorlib",
"System",
"System.Core",
"System.Data",
"RestSharp",
"QuarterMaster",
"AutoPlayLibrary",
"ExtrasLibrary",
"GoogleAdWordsLibrary",
"GoogleDriveLibrary",
"JSONSerialisationLibrary",
"SeleniumLibrary",
"WebServerLibrary",
"WordPressLibrary",
"WorkFlowMaxLibrary",
"XeroLibrary"));
This works fine when run interactively. What happens when run from Task Scheduler is that the CSHost
defines okay but the CSExtendedHost
kills the EXE and throws errors in the Event log.
The errors in Event Viewer aren't exactly helpful, viz
Application: RulesetRunner.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileLoadException
at System.Reflection.RuntimeAssembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.RuntimeAssembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
at System.Reflection.RuntimeAssembly.InternalLoad(System.String, System.Security.Policy.Evidence, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean)
at System.Reflection.RuntimeAssembly.InternalLoad(System.String, System.Security.Policy.Evidence, System.Threading.StackCrawlMark ByRef, Boolean)
at System.Reflection.Assembly.Load(System.String)
at Microsoft.ClearScript.HostTypeCollection.AddAssembly(System.String)
at System.Array.ForEach[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.__Canon[], System.Action`1<System.__Canon>)
at Microsoft.ClearScript.HostTypeCollection..ctor(System.String[])
at RulesetRunner.Program.Main(System.String[])
It's only been through trial and error that I've established that its ExtendedHostFunctions. If I comment it out and retry something else triggers the problem, in this case RestSharp
but the DLL is in the right place and even on the PATH.