ClearScript ExtendedHostFunctions kills EXE when run from Task Scheduler? - c#

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.

Related

How can I copy a .NET desktop app to another machine? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have an application on my desktop. The application folder contains a .exe file and .config file.
The config file shows Rsa Key.
I am swapping PC's and would like to run the application on new PC. I have tried simply copying the folder over but the app wont run. The windows event viewer error:
Application: procoach.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception.
Exception Info: System.Configuration.ConfigurationErrorsException at System.Configuration.RsaProtectedConfigurationProvider.ThrowBetterException(Boolean)
at System.Configuration.RsaProtectedConfigurationProvider.GetCryptoServiceProvider(Boolean, Boolean)
at System.Configuration.RsaProtectedConfigurationProvider.Decrypt(System.Xml.XmlNode)
at System.Configuration.ProtectedConfigurationSection.DecryptSection(System.String, System.Configuration.ProtectedConfigurationProvider)
at System.Configuration.BaseConfigurationRecord.DecryptConfigSection(System.Configuration.ConfigXmlReader, System.Configuration.ProtectedConfigurationProvider)
Exception Info: System.Configuration.ConfigurationErrorsException at System.Configuration.BaseConfigurationRecord.EvaluateOne(System.String[], System.Configuration.SectionInput, Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object)
at System.Configuration.BaseConfigurationRecord.Evaluate(System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, Boolean, Boolean, System.Object ByRef, System.Object ByRef)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef)
at System.Configuration.Configuration.GetSection(System.String)
at procoach.authentication.login.ProtectSection(System.String)
at procoach.authentication.login..ctor()
Exception Info: System.Windows.Markup.XamlParseException
at System.Windows.Markup.XamlReader.RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri)
at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
at System.Windows.Application.DoStartup() at System.Windows.Application.<.ctor>b__1_0(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
at System.Windows.Application.RunDispatcher(System.Object)
at System.Windows.Application.RunInternal(System.Windows.Window)
at procoach.App.Main()
I also have .NET framewirk installed and up to date on target achine
How do i go about copying the app to a different. I do have access to server where the database and source code are hosted.
I have zero experience in deploying/compiling .NET apps.
It looks like the RSA key that was generated may have been machine specific. Most likely you will need a new one generated for your new machine. Another option would be to take an image of the machine and try to run it in something like virtual box. Lastly, you could look at figuring out what is making it machine-specific, something like values in the registry or mac addresses for the piece needed to get it working. But that last one is like looking for a needle in a very large haystack... Best option is the first, figure out how to regenerate the RSA key.

How to install exe in another system?

When I install project using Microsoft installer setup the generated executable exe file is unable to open on another system. Getting an error in Event viewer windows log application file.
Exception Info:(Event 1026.Net Runtime error)
System.IO.DirectoryNotFoundException at
System.IO.__Error.WinIOError(Int32, System.String) at
System.IO.FileStream.Init(System.String, System.IO.FileMode,
System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32,
System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean,
Boolean, Boolean) at System.IO.FileStream..ctor(System.String,
System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32,
System.IO.FileOptions, System.String, Boolean, Boolean, Boolean) at
System.IO.StreamReader..ctor(System.String, System.Text.Encoding,
Boolean, Int32, Boolean) at
System.IO.File.InternalReadAllText(System.String,
System.Text.Encoding, Boolean) at
System.IO.File.ReadAllText(System.String)

Windows service start issue with ServiceController class for few machines

I'm having a window service and tried to start it by using ServiceController class from an windows application and it's working fine for few systems, but this is failing in few systems and giving exception like below.
Below is the sample code that I've written to start the service, also I don't want to do any manual changes to the target machine in order to start the service.
ServiceController service = new ServiceController("SampleService");
if (service.Status.Equals(ServiceControllerStatus.Running) || service.Status.Equals(ServiceControllerStatus.StartPending))
{
Bservice.Stop();
}
service.WaitForStatus(ServiceControllerStatus.Stopped);
service.Start(arguments);
service.WaitForStatus(ServiceControllerStatus.Running);
Am I missing anything from the code snippet? or please help me out how can i get rid of this.
Even I've commented out all the code in the service like it's empty service now, but with code and without code I'm getting same below error any idea??
Application: ECApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
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.Assembly.Load(System.Reflection.AssemblyName)
at System.Windows.Baml2006.Baml2006SchemaContext.ResolveAssembly(BamlAssembly)
at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlTypeToType(BamlType)
at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(BamlType, Int16)
at System.Windows.Baml2006.Baml2006SchemaContext.GetXamlType(Int16)
at System.Windows.Baml2006.Baml2006Reader.Process_ConstructorParameterType()
at System.Windows.Baml2006.Baml2006Reader.Process_OneBamlRecord()
at System.Windows.Baml2006.Baml2006Reader.ReadKeys()
at System.Windows.ResourceDictionary.SetDeferrableContent(System.Windows.DeferrableContent)
at System.Windows.Baml2006.WpfSharedBamlSchemaContext+<>c.<Create_BamlProperty_ResourceDictionary_DeferrableContent>b__297_0(System.Object, System.Object)
at System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(System.Object, System.Object)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Xaml.XamlMember, System.Object, System.Object)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Object, System.Xaml.XamlMember, System.Object)
Exception Info: System.Windows.Markup.XamlParseException
at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
at System.Windows.Application.LoadComponent(System.Object, System.Uri)
at ECApp.Presentation.App.InitializeComponent()
at ECApp.Presentation.App.Main()
The above exception is coming only when I install service using commad 'sc create "service name" ...' but when I install service using 'Installutil.exe "service"' then I'm getting no issues don't know why? Any reasons??

c# WPF - File Access is Denied

I'm trying to make an msi file for my wpf soln through InstallShield and inside this WPF soln I'm trying to access an .rtf file using this code:
string rtfFilePath = #"Help.rtf";
using (var fs = new FileStream(rtfFilePath, FileMode.Open)){ ... }
During debug mode it works fine but when I have already created an msi file and run the msi file and install it on my machine into the path to C:/Program Files/Company_Name/Project_Name and launch the exe program file with the rtf file on the same directory/folder where the exe file is also located.
I'm getting an exception message of "Access to the path 'C:/Program Files/Company_Name/Project_Name\Help.rtf' is denied."
And an event viewer exception of:
Description: The process was terminated due to an unhandled exception.
Exception Info:
System.UnauthorizedAccessException
at System.IO.__Error.WinIOError(Int32, System.String)
at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)
at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean)
at System.IO.FileStream..ctor(System.String, System.IO.FileMode)
at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawMouseActions, Int32, Int32, Int32)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr, MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
at System.Windows.Application.RunDispatcher(System.Object)
at System.Windows.Application.RunInternal(System.Windows.Window)
at Project_Name.App.Main()
What am I missing so far?
Well accessing Program Files requires Admin Access so you have to run your program as administrator.
You can make your program to require administrator privilege when running, to do this please see the following question:
How do I force my .NET application to run as administrator?
P.S.: Note that if possible you can avoid accessing restricted areas like Program Files and then you won't need to grant this privilege.

InteropServices.COMException when using Fanuc Robotics library

I'm having problems running application on target machine. App uses Fanuc Robotics library: FANUC Robotics Controller Interface.
In Reference manager path for this control is C:\Program Files (x86)\FANUC\Shared\Robot Server\frrobot.exe. In Reference properties for FRRobot I see it's name is Interop.FRRobot, file type ActiveX and it's path is \obj\Release\Interop.FRRobot.dll. Besides this file there is also Interop.FRVirtual.dll.
I copied both files to target computer to system32, SysWOW64 and directory with myapp.exe file but app crashes at startup with error I pasted below.
What do I need to do to have app running on target machine?
Application is running on my machine without problems and if I comment out parts of program where I use FRRobot classes app runs on target machine also.
Application: HMI.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException
at System.RuntimeTypeHandle.CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)
at System.RuntimeType.CreateInstanceSlow(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
at System.Activator.CreateInstance(System.Type, Boolean)
at System.Activator.CreateInstance(System.Type)
at HMI.MainWindow..ctor()
Exception Info: System.Windows.Markup.XamlParseException
at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
at System.Windows.Application.LoadComponent(System.Uri, Boolean)
at System.Windows.Application.DoStartup()
at System.Windows.Application.<.ctor>b__1_0(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
at System.Windows.Application.RunDispatcher(System.Object)
at System.Windows.Application.RunInternal(System.Windows.Window)
at System.Windows.Application.Run(System.Windows.Window)
at HMI.App.Main()

Categories