[英]System.AggregateException: One or more errors occurred. ---> System.Web.Services.Protocols.SoapException
[英]System.AggregateException was unhandled. Message=One or more errors occurred. InnerException: System.Windows.Markup.XamlParseException
目前,我正在嘗試創建Windows Service應用程序。 當我按照本文所述將服務設置為調試時,它可以正常工作:
http://www.codeproject.com/Articles/10153/Debugging-Windows-Services-under-Visual-Studio-NET
然后,如果我嘗試以這種方式設置Windows服務:
using System;
using System.Collections.Generic;
using System.Linq;
using ServiceProcess.Helpers;
using System.ServiceProcess;
using System.Text;
using System.IO;
namespace MyNamespace
{
static class Program
{
private static readonly List<ServiceBase> _servicesToRun =
new List<ServiceBase>();
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
MyService service = new MyService();
_servicesToRun.Add(service);
if (Environment.UserInteractive)
{
_servicesToRun.ToArray().LoadServices();
}
else
{
ServiceBase.Run(_servicesToRun.ToArray());
}
}
}
}
然后,在調試時,在_servicesToRun.ToArray()。LoadServices()行上,我收到以下異常:
System.AggregateException was unhandled
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at ServiceProcess.Helpers.ServiceRunner.LoadServices(IEnumerable`1 services)
at EnvisionWatchdog.Program.Main() in c:\DevProjects\Data Service\DataService\EnvisionWatchdog\Program.cs:line 26
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Windows.Markup.XamlParseException
HResult=-2146233087
Message=Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.
Source=PresentationFramework
LineNumber=0
LinePosition=0
StackTrace:
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at ServiceProcess.Helpers.App.InitializeComponent()
at ServiceProcess.Helpers.ServiceRunner.<>c__DisplayClass5.<LoadServices>b__1()
at System.Threading.Tasks.Task.Execute()
InnerException: System.NotImplementedException
HResult=-2147467263
Message=The method or operation is not implemented.
Source=PresentationFramework
StackTrace:
at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(BamlType bamlType, Int16 typeId)
at System.Windows.Baml2006.Baml2006SchemaContext.GetXamlType(Int16 typeId)
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(DeferrableContent deferrableContent)
at System.Windows.Baml2006.WpfSharedBamlSchemaContext.<Create_BamlProperty_ResourceDictionary_DeferrableContent>b__168(Object target, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
InnerException:
奇怪的是,該應用程序是Windows服務,在任何地方都不包含任何WPF代碼。 有沒有人有什么建議? TIA。
堆棧跟蹤顯示您的環境中是否存在ServiceProcess.Helpers
Windows Service Helper 。 根據該頁面,它依賴於reactui-xaml。 這可能是與WPF相關的異常的來源。
不依賴NuGet軟件包的外部依賴的方法是:
static class Program
{
public static MyService ServiceInstance;
static Program()
{
ServiceInstance = new MyService ();
}
static void Main()
{
if (System.Diagnostics.Debugger.IsAttached)
{
ServiceInstance.StartInAttachedDebugger();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
else
{
ServiceBase.Run(ServiceInstance);
}
}
}
在MyService
類中實現StartInAttachedDebugger
。
public void StartInAttachedDebugger()
{
OnStart(null);
}
然后,您可以按預期從Visual Studio開始調試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.