少数机器的ServiceController类的Windows服务启动问题

时间:2019-01-22 13:28:11

标签: c# windows-services

我有一个窗口服务,并试图通过Windows应用程序中的ServiceController类来启动它,它在少数系统上运行良好,但这在少数系统上失败了,并给出了如下所示的异常。

Error that I'm getting

下面是我为启动该服务而编写的示例代码,我也不想对目标计算机进行任何手动更改以启动该服务。

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

我是否缺少代码段中的任何内容?还是请帮我解决这个问题。

即使我已经注释掉了服务中的所有代码,就像它现在是空服务一样,但是使用代码和不使用代码,我都会在错误以下得到相同的提示吗?

    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()

仅当我使用commad'sc create“服务名称” ...“安装服务时才会出现上述异常,但是当我使用'Installutil.exe”服务“'安装服务时,我没有遇到任何问题知道为什么?有什么原因吗?

0 个答案:

没有答案