0

在我的 C# 项目中,我有以下内容

    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"));

这在交互运行时工作正常。从任务计划程序运行时发生的情况是CSHost定义没问题,但会CSExtendedHost杀死 EXE 并在事件日志中引发错误。

事件查看器中的错误并不完全有帮助,即

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[])

我只是通过反复试验才确定它的 ExtendedHostFunctions。如果我将其注释掉并重试其他东西会触发问题,在这种情况下RestSharp,但 DLL 位于正确的位置,甚至位于 PATH 上。

4

0 回答 0