.net 4.0 DurableInstance中的System.Runtime.CallbackException
最近,我开始在我的工作流应用程序中遇到此异常 System.Runtime.CallbackException,System.Runtime.DurableInstance,版本=4.0.0.0,区域性=中立,PublicKeyToken=31bf3856ad364e35 用户回调引发异常。检查异常堆栈和内部异常以确定失败的回调。 我通过运行以下类的Windows服务承载我的服务:.net 4.0 DurableInstance中的System.Runtime.CallbackException,.net-4.0,windows-services,workflow,workflow-foundation-4,workflowservice,.net 4.0,Windows Services,Workflow,Workflow Foundation 4,Workflowservice,最近,我开始在我的工作流应用程序中遇到此异常 System.Runtime.CallbackException,System.Runtime.DurableInstance,版本=4.0.0.0,区域性=中立,PublicKeyToken=31bf3856ad364e35 用户回调引发异常。检查异常堆栈和内部异常以确定失败的回调。 我通过运行以下类的Windows服务承载我的服务: public class WorkflowHost { private readonly List<
public class WorkflowHost
{
private readonly List<string> _services = new List<string>();
private readonly Dictionary<string, WorkflowServiceHost> _hosts = new Dictionary<string, WorkflowServiceHost>();
public WorkflowHost(IList<string> serviceNames)
{
foreach (string serviceName in serviceNames)
{
_services.Add(serviceName);
}
}
public void Start()
{
if (_hosts.Count > 0)
{
Stop();
}
foreach(string serviceName in _services)
{
WorkflowService service = LoadService(serviceName);
WorkflowServiceHost host = new WorkflowServiceHost(service);
host.Faulted += new EventHandler(host_Faulted);
try
{
host.Open();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
_hosts.Add(serviceName, host);
}
}
void host_Faulted(object sender, EventArgs e)
{
Debug.WriteLine("Service Faulted");
Start();
}
public void Stop()
{
if (_hosts.Count > 0)
{
foreach (string serviceName in _services)
{
IDisposable host = _hosts[serviceName];
host.Dispose();
}
_hosts.Clear();
}
}
private WorkflowService LoadService(String xamlxName)
{
string fullFilePath = Path.Combine(@"..\..\..\Services\Sales Funnel Workflow", xamlxName);
WorkflowService service = XamlServices.Load(fullFilePath) as WorkflowService;
if (service != null)
{
return service;
}
else
{
throw new NullReferenceException(string.Format("Unable to load service definition from {0}", fullFilePath));
}
}
}
公共类工作流主机
{
私有只读列表_services=new List();
专用只读词典_hosts=new Dictionary();
公共工作流主机(IList ServiceName)
{
foreach(serviceNames中的字符串serviceName)
{
_services.Add(serviceName);
}
}
公开作废开始()
{
如果(_hosts.Count>0)
{
停止();
}
foreach(字符串serviceName in_services)
{
WorkflowService=LoadService(serviceName);
WorkflowServiceHost主机=新的WorkflowServiceHost(服务);
host.Faulted+=新的EventHandler(host\u Faulted);
尝试
{
host.Open();
}
捕获(例外e)
{
Debug.WriteLine(e.Message);
}
_添加(serviceName,host);
}
}
无效主机\出现故障(对象发送方,事件参数e)
{
Debug.WriteLine(“服务故障”);
Start();
}
公共停车场()
{
如果(_hosts.Count>0)
{
foreach(字符串serviceName in_services)
{
IDisposable主机=_主机[serviceName];
host.Dispose();
}
_hosts.Clear();
}
}
私有WorkflowService加载服务(字符串xamlxName)
{
字符串fullFilePath=Path.Combine(@.\..\..\Services\Sales漏斗工作流),xamlxName);
WorkflowService=XamlServices.Load(fullFilePath)作为WorkflowService;
if(服务!=null)
{
回程服务;
}
其他的
{
抛出新的NullReferenceException(string.Format(“无法从{0},fullFilePath)加载服务定义”);
}
}
}
以下是异常的完整堆栈跟踪:
<StackTrace>
at System.ServiceModel.Channels.CommunicationObject.OnFaulted()
at System.ServiceModel.Channels.CommunicationObject.Fault()
at System.ServiceModel.Channels.CommunicationObject.Fault(Exception exception)
at System.ServiceModel.Activities.Dispatcher.DurableInstanceManager.WaitAndHandleStoreEventsCallback(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.Runtime.AsyncResult.AsyncCompletionWrapperCallback(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.Runtime.DurableInstancing.InstanceHandle.WaitForEventsAsyncResult.Canceled()
at System.Runtime.DurableInstancing.InstanceHandle.Free()
at System.Activities.DurableInstancing.SqlWorkflowInstanceStoreLock.MarkInstanceOwnerLost(Int64 surrogateLockOwnerId)
at System.Activities.DurableInstancing.SqlWorkflowInstanceStoreLock.MarkInstanceOwnerLost(Int64 surrogateLockOwnerId, Boolean hasModificationLock)
at System.Activities.DurableInstancing.LockRenewalTask.HandleError(Exception exception)
at System.Activities.DurableInstancing.PersistenceTask.CommandCompletedCallback(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously, Exception exception)
at System.Activities.DurableInstancing.SqlWorkflowInstanceStoreAsyncResult.StartOperation()
at System.Activities.DurableInstancing.SqlWorkflowInstanceStoreAsyncResult.StartOperationCallback(Object state)
at System.Runtime.ActionItem.DefaultActionItem.Invoke()
at System.Runtime.ActionItem.CallbackHelper.InvokeWithoutContext(Object state)
at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace>
<ExceptionString>System.Runtime.CallbackException: A user callback threw an exception. Check the exception stack and inner exception to determine the callback that failed. ---> System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Activities.WorkflowServiceHost, cannot be used for communication because it is in the Faulted state.
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.System.IDisposable.Dispose()
at Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.Stop() in C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service\WorkflowHost.cs:line 67
at Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.Start() in C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service\WorkflowHost.cs:line 30
at Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.host_Faulted(Object sender, EventArgs e) in C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service\WorkflowHost.cs:line 57
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.ServiceModel.Channels.CommunicationObject.OnFaulted()
--- End of inner exception stack trace ---</ExceptionString>
<InnerException>
<ExceptionType>System.ServiceModel.CommunicationObjectFaultedException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The communication object, System.ServiceModel.Activities.WorkflowServiceHost, cannot be used for communication because it is in the Faulted state.</Message>
<StackTrace>
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.System.IDisposable.Dispose()
at Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.Stop() in C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service\WorkflowHost.cs:line 67
at Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.Start() in C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service\WorkflowHost.cs:line 30
at Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.host_Faulted(Object sender, EventArgs e) in C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service\WorkflowHost.cs:line 57
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.ServiceModel.Channels.CommunicationObject.OnFaulted()
</StackTrace>
<ExceptionString>System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Activities.WorkflowServiceHost, cannot be used for communication because it is in the Faulted state.
at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.System.IDisposable.Dispose()
at Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.Stop() in C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service\WorkflowHost.cs:line 67
at Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.Start() in C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service\WorkflowHost.cs:line 30
at Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.host_Faulted(Object sender, EventArgs e) in C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service\WorkflowHost.cs:line 57
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.ServiceModel.Channels.CommunicationObject.OnFaulted()</ExceptionString>
</InnerException>
</Exception>
位于System.ServiceModel.Channels.CommunicationObject.OnFaulted()处
在System.ServiceModel.Channels.CommunicationObject.Fault()处
在System.ServiceModel.Channels.CommunicationObject.Fault处(异常)
位于System.ServiceModel.Activities.Dispatcher.DurableInstanceManager.WaitAndHandleStoreEventsCallback(IAsyncResult结果)
在System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult结果)中
在System.Runtime.AsyncResult.Complete(布尔同步完成)
在System.Runtime.AsyncResult.AsyncCompletionWrapperCallback(IAsyncResult结果)时
在System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult结果)中
在System.Runtime.AsyncResult.Complete(布尔同步完成)
在System.Runtime.DurableInstance.InstanceHandle.WaitForEventsAsyncResult.Cancelled()中
在System.Runtime.DurableInstance.InstanceHandle.Free()中
位于System.Activities.DurableInstance.SqlWorkflowInstanceStoreLock.MarkInstanceOwnerLost(Int64代理锁所有者ID)
位于System.Activities.DurableInstance.SqlWorkflowInstanceStoreLock.MarkInstanceOwnerLost(Int64代理锁所有者ID,布尔值hasModificationLock)
位于System.Activities.DurableInstance.LockRenewalTask.HandleError(异常)
位于System.Activities.DurableInstance.PersistenceTask.CommandCompletedCallback(IAsyncResult结果)
在System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult结果)中
在System.Runtime.AsyncResult.Complete(布尔同步完成)
在System.Runtime.AsyncResult.Complete(布尔同步完成,异常异常)
位于System.Activities.DurableInstance.SqlWorkflowInstanceStoreAsyncResult.StartOperation()处
位于System.Activities.DurableInstance.SqlWorkflowInstanceStoreAsyncResult.StartOperationCallback(对象状态)
在System.Runtime.ActionItem.DefaultActionItem.Invoke()中
在System.Runtime.ActionItem.CallbackHelper.InvokeWithoutContext(对象状态)中
在System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32错误代码,UInt32个字节,NativeOverlapped*NativeOverlapped)
在System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32错误,UInt32字节读取,NativeOverlapped*NativeOverlapped)
在System.Threading.\u IOCompletionCallback.PerformiCompletionCallback(UInt32错误代码,UInt32个字节,本机重叠*pOVERLAP)
System.Runtime.CallbackException:用户回调引发异常。检查异常堆栈和内部异常以确定失败的回调。--System.ServiceModel.CommunicationObjectFaultedException:通信对象System.ServiceModel.Activities.WorkflowServiceHost无法用于通信,因为它处于故障状态。
在System.ServiceModel.Channels.CommunicationObject.Close处(TimeSpan超时)
位于System.ServiceModel.ServiceHostBase.System.IDisposable.Dispose()处
在C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.Stop()中
在C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.Start()中的Zeller.SalesFunnel.Start()处:第30行
在C:\Projects\TFS\Zeller Corp Toolkit\Main\Toolkit\Services\ZSalesFunnelService\Zeller.SalesFunnel.WorkFlow.Service.WorkflowHost.host中出现错误(对象发送方,事件参数e):第57行
在System.EventHandler.Invoke(对象发送方,EventArgs e)
在System.ServiceModel.Channels.CommunicationsObjec