ObjectDataSource 调用 WCF 服务抛出无法访问处置对象
ObjectDataSource Call WCF service throw cannot access dispose object
我在 Window Server 2012 中的 IIS 上部署程序时遇到程序抛出无法访问处置对象的问题。
根据代码,代码可以运行在我的PC开发和生产中正常但是当我部署到测试服务器时出现问题
症状是我可以 运行 在部署后的第一时间很好地编程,然后当我重新进入它抛出的页面时无法访问处理对象。
我也检查了使用 soap 重复发送请求的服务,但没有发现问题,现在在不同的 PC 和服务器上测试后它也可以 运行。
我不确定我必须对配置或服务器规范做更多的事情。
因为其他人可以 运行 拥有超过 8GB 的 ram 但在测试服务器中发现问题只有 4GB 的 ram 或者我必须编辑我的代码?
将数据源绑定到服务的代码部分
#region Employeeprofile
this.EmployeeProfileDataSource.DataMember = "GetWF_30EmployeeProfile";
this.EmployeeProfileDataSource.DataSource = typeof(THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager);
this.EmployeeProfileDataSource.Name = "EmployeeProfileDataSource";
this.EmployeeProfileDataSource.Parameters.AddRange(new Telerik.Reporting.ObjectDataSourceParameter[] {
new Telerik.Reporting.ObjectDataSourceParameter("employeeNo", typeof(string), empNo)});
report.DataSource = this.EmployeeProfileDataSource;
#endregion
#region Spouse
this.SpouseDataSource.DataMember = "GetWF_30SummaryMarriageFromBeforeApprove";
this.SpouseDataSource.DataSource = typeof(THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager);
this.SpouseDataSource.Name = "SpouseDataSource";
this.SpouseDataSource.Parameters.AddRange(new Telerik.Reporting.ObjectDataSourceParameter[] {
new Telerik.Reporting.ObjectDataSourceParameter("employeeNo", typeof(string), empNo)});
然后EmployeeProfilesReportManager 启动服务并调用
public EmployeeProfilesReportManager()
{
_service =Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<IService.IReportEmployeeProfileService>();
_logExceptionService = Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<IService.ILogException>();
}
在服务层它实现了 IDisposable
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class ReportEmployeeProfileService : IReportEmployeeProfileService, IDisposable, ICommunicationObject
{
}
还有代码句柄Dispose
protected virtual void Dispose(bool disposing)
{
if (disposed){
return;
}
if (disposing)
{
handle.Dispose();
}
disposed = true;
}
public void Abort()
{
_dbContext.Database.Connection.Close();
_dbContext.Dispose();
Dispose(true);
}
public void Close()
{
_dbContext.Database.Connection.Close();
_dbContext.Dispose();
Dispose(true);
}
我希望有问题的服务器可以 运行 像其他服务器一样正常。
谢谢。
使用诊断工具后我收到了这条消息
DetailID = 18
Count: 1
Type: System.ObjectDisposedException
Message: Cannot access a disposed object.
Stack:
[HelperMethodFrame]
System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable()
System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
System.ServiceModel.Channels.ServiceChannel+CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(System.ServiceModel.Channels.ServiceChannel, System.TimeSpan)
System.ServiceModel.Channels.ServiceChannel+CallOnceManager.CallOnce(System.TimeSpan, CallOnceManager)
System.ServiceModel.Channels.ServiceChannel.EnsureOpened(System.TimeSpan)
System.ServiceModel.Channels.ServiceChannel.Call(System.String, Boolean, System.ServiceModel.Dispatcher.ProxyOperationRuntime, System.Object[], System.Object[], System.TimeSpan)
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(System.Runtime.Remoting.Messaging.IMethodCallMessage, System.ServiceModel.Dispatcher.ProxyOperationRuntime)
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(System.Runtime.Remoting.Messaging.IMessage)
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(System.Runtime.Remoting.Proxies.MessageData ByRef, Int32)
[TPMethodFrame]
THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager.GetWF_30EmployeeProfile(System.String)
[DebuggerU2MCatchHandlerFrame]
[HelperMethodFrame_PROTECTOBJ]
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].TryResolveDataSourceInstance(Boolean, System.Object ByRef, System.String ByRef)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource(Boolean)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource()
Telerik.Reporting.Processing.Data.ObjectDataEnumerable.GetEnumerator()
Telerik.Reporting.Processing.Data.ResultSetAdapter.Fill(Telerik.Reporting.Processing.Data.ResultSet, System.Collections.Generic.IEnumerable`1<Telerik.Reporting.Processing.IDataObject>)
Telerik.Reporting.Processing.Data.MultidimentionalDataProvider.Execute(Telerik.Reporting.Processing.Data.MultidimensionalQuery)
Telerik.Reporting.Processing.Report.ResolveData()
Telerik.Reporting.Processing.Report.ProcessItemCore()
Telerik.Reporting.Processing.Report.ProcessItem()
Telerik.Reporting.Processing.ReportItemBase.ProcessElement()
Telerik.Reporting.Processing.ProcessingElement.Process(Telerik.Reporting.Processing.Data.IDataMember)
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, Telerik.Reporting.Processing.IRenderingContext)
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, System.Collections.Hashtable, Telerik.Reporting.Processing.IRenderingContext)
Telerik.Reporting.Services.Engine.ReportRenderer.Render(Telerik.Reporting.Services.Engine.ReportRendererArgs)
Telerik.Reporting.Services.Engine.Rendering.RenderWithCulture(Telerik.Reporting.Services.Engine.ReportRendererArgs)
Telerik.Reporting.Services.Engine.Rendering.ThreadFunc(System.Object)
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
System.Threading.ThreadHelper.ThreadStart(System.Object)
[GCFrame]
[DebuggerU2MCatchHandlerFrame]
[ContextTransitionFrame]
[DebuggerU2MCatchHandlerFrame]
DetailID = 19
Count: 1
Type: System.ObjectDisposedException
Message: Cannot access a disposed object.
Stack:
[HelperMethodFrame]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(System.Runtime.Remoting.Proxies.MessageData ByRef, Int32)
[TPMethodFrame]
THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager.GetWF_30EmployeeProfile(System.String)
[DebuggerU2MCatchHandlerFrame]
[HelperMethodFrame_PROTECTOBJ]
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].TryResolveDataSourceInstance(Boolean, System.Object ByRef, System.String ByRef)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource(Boolean)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource()
Telerik.Reporting.Processing.Data.ObjectDataEnumerable.GetEnumerator()
Telerik.Reporting.Processing.Data.ResultSetAdapter.Fill(Telerik.Reporting.Processing.Data.ResultSet, System.Collections.Generic.IEnumerable`1<Telerik.Reporting.Processing.IDataObject>)
Telerik.Reporting.Processing.Data.MultidimentionalDataProvider.Execute(Telerik.Reporting.Processing.Data.MultidimensionalQuery)
Telerik.Reporting.Processing.Report.ResolveData()
Telerik.Reporting.Processing.Report.ProcessItemCore()
Telerik.Reporting.Processing.Report.ProcessItem()
Telerik.Reporting.Processing.ReportItemBase.ProcessElement()
Telerik.Reporting.Processing.ProcessingElement.Process(Telerik.Reporting.Processing.Data.IDataMember)
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, Telerik.Reporting.Processing.IRenderingContext)
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, System.Collections.Hashtable, Telerik.Reporting.Processing.IRenderingContext)
Telerik.Reporting.Services.Engine.ReportRenderer.Render(Telerik.Reporting.Services.Engine.ReportRendererArgs)
Telerik.Reporting.Services.Engine.Rendering.RenderWithCulture(Telerik.Reporting.Services.Engine.ReportRendererArgs)
Telerik.Reporting.Services.Engine.Rendering.ThreadFunc(System.Object)
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
System.Threading.ThreadHelper.ThreadStart(System.Object)
[GCFrame]
[DebuggerU2MCatchHandlerFrame]
[ContextTransitionFrame]
[DebuggerU2MCatchHandlerFrame]
这是来自分析工具
Thread 24 - System ID 3404
Entry point clr!LogHelp_LogAssert+18208
Create time 5/9/2562 19:21:15
Time spent in user mode 0 Days 00:00:00.015
Time spent in kernel mode 0 Days 00:00:00.000
This thread is not fully resolved and may or may not be a problem. Further analysis of these threads may be required.
The thread has evidence of .net exceptions on the stack. Check the Previous .NET Exceptions Report (Exceptions in all .NET Thread Stacks) to view more details of the associated exception
.NET Call Stack
[[HelperMethodFrame]]
System_ServiceModel_ni!System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable()+15a
System_ServiceModel_ni!System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)+b8
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel+CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(System.ServiceModel.Channels.ServiceChannel, System.TimeSpan)+12
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel+CallOnceManager.CallOnce(System.TimeSpan, CallOnceManager)+10d
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel.EnsureOpened(System.TimeSpan)+28
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel.Call(System.String, Boolean, System.ServiceModel.Dispatcher.ProxyOperationRuntime, System.Object[], System.Object[], System.TimeSpan)+1af
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(System.Runtime.Remoting.Messaging.IMethodCallMessage, System.ServiceModel.Dispatcher.ProxyOperationRuntime)+61
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannelProxy.Invoke(System.Runtime.Remoting.Messaging.IMessage)+90
mscorlib_ni!System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(System.Runtime.Remoting.Proxies.MessageData ByRef, Int32)+114
[[TPMethodFrame] (THP.Welfare.IService.IReportEmployeeProfileService.GetWF_30EmployeeProfiles)] THP.Welfare.IService.IReportEmployeeProfileService.GetWF_30EmployeeProfiles(System.String)
THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager.GetWF_30EmployeeProfile(System.String)+59
[[DebuggerU2MCatchHandlerFrame]]
[[HelperMethodFrame_PROTECTOBJ] (System.RuntimeMethodHandle.InvokeMethod)] System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
mscorlib_ni!System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])+80
mscorlib_ni!System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)+92
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].TryResolveDataSourceInstance(Boolean, System.Object ByRef, System.String ByRef)+2ec
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource(Boolean)+2c
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource()+23
Telerik.Reporting.Processing.Data.ObjectDataEnumerable.GetEnumerator()+1d
Telerik.Reporting.Processing.Data.ResultSetAdapter.Fill(Telerik.Reporting.Processing.Data.ResultSet, System.Collections.Generic.IEnumerable`1)+249
Telerik.Reporting.Processing.Data.MultidimentionalDataProvider.Execute(Telerik.Reporting.Processing.Data.MultidimensionalQuery)+af
Telerik.Reporting.Processing.Report.ResolveData()+256
Telerik.Reporting.Processing.Report.ProcessItemCore()+68
Telerik.Reporting.Processing.Report.ProcessItem()+a0
Telerik.Reporting.Processing.ReportItemBase.ProcessElement()+27
Telerik.Reporting.Processing.ProcessingElement.Process(Telerik.Reporting.Processing.Data.IDataMember)+c4
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, Telerik.Reporting.Processing.IRenderingContext)+590
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, System.Collections.Hashtable, Telerik.Reporting.Processing.IRenderingContext)+1d0
Telerik.Reporting.Services.Engine.ReportRenderer.Render(Telerik.Reporting.Services.Engine.ReportRendererArgs)+bc
Telerik.Reporting.Services.Engine.Rendering.RenderWithCulture(Telerik.Reporting.Services.Engine.ReportRendererArgs)+51
Telerik.Reporting.Services.Engine.Rendering.ThreadFunc(System.Object)+5a
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+160
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+17
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)+52
mscorlib_ni!System.Threading.ThreadHelper.ThreadStart(System.Object)+5d
[[GCFrame]]
[[DebuggerU2MCatchHandlerFrame]]
[[ContextTransitionFrame]]
[[DebuggerU2MCatchHandlerFrame]]
Full Call Stack
KERNELBASE!RaiseException+6c
clr!LogHelp_LogAssert+16565
clr!LogHelp_LogAssert+16363
[[HelperMethodFrame]]
System_ServiceModel_ni!System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable()+15a
System_ServiceModel_ni!System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)+b8
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel+CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(System.ServiceModel.Channels.ServiceChannel, System.TimeSpan)+12
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel+CallOnceManager.CallOnce(System.TimeSpan, CallOnceManager)+10d
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel.EnsureOpened(System.TimeSpan)+28
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel.Call(System.String, Boolean, System.ServiceModel.Dispatcher.ProxyOperationRuntime, System.Object[], System.Object[], System.TimeSpan)+1af
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(System.Runtime.Remoting.Messaging.IMethodCallMessage, System.ServiceModel.Dispatcher.ProxyOperationRuntime)+61
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannelProxy.Invoke(System.Runtime.Remoting.Messaging.IMessage)+90
mscorlib_ni!System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(System.Runtime.Remoting.Proxies.MessageData ByRef, Int32)+114
clr!GetMetaDataInternalInterface+1e30e
clr!GetMetaDataPublicInterfaceFromInternal+2a8f1
clr!PreBindAssemblyEx+1b12d
[[TPMethodFrame] (THP.Welfare.IService.IReportEmployeeProfileService.GetWF_30EmployeeProfiles)] THP.Welfare.IService.IReportEmployeeProfileService.GetWF_30EmployeeProfiles(System.String)
clr!GetMetaDataInternalInterface+1e251
THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager.GetWF_30EmployeeProfile(System.String)+59
clr+3753
clr+361c
clr!GetMetaDataInternalInterface+31766
clr!GetMetaDataInternalInterface+31550
[[DebuggerU2MCatchHandlerFrame]]
[[HelperMethodFrame_PROTECTOBJ] (System.RuntimeMethodHandle.InvokeMethod)] System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
mscorlib_ni!System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])+80
mscorlib_ni!System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)+92
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].TryResolveDataSourceInstance(Boolean, System.Object ByRef, System.String ByRef)+2ec
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource(Boolean)+2c
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource()+23
Telerik.Reporting.Processing.Data.ObjectDataEnumerable.GetEnumerator()+1d
Telerik.Reporting.Processing.Data.ResultSetAdapter.Fill(Telerik.Reporting.Processing.Data.ResultSet, System.Collections.Generic.IEnumerable`1<Telerik.Reporting.Processing.IDataObject>)+249
Telerik.Reporting.Processing.Data.MultidimentionalDataProvider.Execute(Telerik.Reporting.Processing.Data.MultidimensionalQuery)+af
Telerik.Reporting.Processing.Report.ResolveData()+256
Telerik.Reporting.Processing.Report.ProcessItemCore()+68
Telerik.Reporting.Processing.Report.ProcessItem()+a0
Telerik.Reporting.Processing.ReportItemBase.ProcessElement()+27
Telerik.Reporting.Processing.ProcessingElement.Process(Telerik.Reporting.Processing.Data.IDataMember)+c4
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, Telerik.Reporting.Processing.IRenderingContext)+590
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, System.Collections.Hashtable, Telerik.Reporting.Processing.IRenderingContext)+1d0
Telerik.Reporting.Services.Engine.ReportRenderer.Render(Telerik.Reporting.Services.Engine.ReportRendererArgs)+bc
Telerik.Reporting.Services.Engine.Rendering.RenderWithCulture(Telerik.Reporting.Services.Engine.ReportRendererArgs)+51
Telerik.Reporting.Services.Engine.Rendering.ThreadFunc(System.Object)+5a
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+160
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+17
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)+52
mscorlib_ni!System.Threading.ThreadHelper.ThreadStart(System.Object)+5d
clr+3753
clr+361c
clr+44d3
clr!TranslateSecurityAttributes+11f684
[[GCFrame]]
clr+6810
clr+67c0
clr+6705
[[DebuggerU2MCatchHandlerFrame]]
clr+71b0
clr+725e
[[ContextTransitionFrame]]
clr+7193
clr+67c0
clr+6705
[[DebuggerU2MCatchHandlerFrame]]
clr+6947
clr!TranslateSecurityAttributes+11f29f
clr!LogHelp_LogAssert+1827e
kernel32!BaseThreadInitThunk+22
ntdll!RtlUserThreadStart+34
Exception Information
In w3wp__ThaihealthWelfare__PID__2376__Date__09_05_2019__Time_07_21_19PM__859__First Chance System.ObjectDisposedException.dmp the assembly instruction at KERNELBASE!RaiseException in C:\Windows\System32\KERNELBASE.dll from Microsoft Corporation has caused a CLR Exception on thread 24 with the following error information:
Type: System.ObjectDisposedException
Message: Cannot access a disposed object.
This exception originated from System_ServiceModel_ni!System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable().
Module Information
Image Name: C:\Windows\assembly\NativeImages_v4.0.30319_64\System.ServiceModeld239193fcf663b211916bd928cfaeb1\System.ServiceModel.ni.dll Symbol Type: None
Base address: 0x00000000`00005a4d Time Stamp: Fri Nov 06 10:20:22 2015
Checksum: 0x00000000`00000000 Comments: Flavor=Retail
COM DLL: False Company Name: Microsoft Corporation
ISAPIExtension: False File Description: System.ServiceModel.dll
ISAPIFilter: False File Version: 4.6.1055.0 built by: NETFXREL2
Managed DLL: True Internal Name: System.ServiceModel.dll
VB DLL: False Legal Copyright: ? Microsoft Corporation. All rights reserved.
Loaded Image Name: System.ServiceModel.ni.dll Legal Trademarks:
Mapped Image Name: Original filename: System.ServiceModel.dll
Module name: System_ServiceModel_ni Private Build: DDBLD400
Single Threaded: False Product Name: Microsoft? .NET Framework
Module Size: 23.41 MBytes Product Version: 4.6.1055.0
Symbol File Name: System.ServiceModel.ni.dll Special Build: &
after following the answer now I can solve the problem with edit my code as
#region Field
private readonly Owned<IService.IReportEmployeeProfileService> _service;
private readonly Owned<IService.ILogException> _logExceptionService;
#endregion
#region Constructor
public EmployeeProfilesReportManager()
{
_service = Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<Owned<IService.IReportEmployeeProfileService>>();
_logExceptionService = Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<Owned<IService.ILogException>>();
}
#endregion
并且在我这样调用服务的所有方法中
public List<SummaryMarriageInfoBeforeApproveModel> GetSummaryMarriageFromBeforeApprove(string employeeNo)
{
var result = _service.Value.GetSummaryMarriageFromBeforeApprove(employeeNo);
_service.Dispose();
_logExceptionService.Dispose();
return result;
}
次要免责声明:我知道 Autofac,但我从未使用过 Telerik 报告服务引擎。但我能猜到发生了什么。
您的情况似乎是 threading/race。
在评论中,您注意到[为了便于阅读而格式化]:
in in startup.cs have create channel as singleton
builder.Register(c => new ChannelFactory<T>("DefaultService")).SingleInstance();
builder.Register(c => c.Resolve<ChannelFactory<T>>().CreateChannel()).UseWcfSafeRelease();
我假设 <T>
是您实际使用的缩写。
我也看到了这个片段:
public EmployeeProfilesReportManager()
{
_service =Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<IService.IReportEmployeeProfileService>();
_logExceptionService = Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<IService.ILogException>();
}
报表管理器正在使用 MVC 依赖项解析器上的服务位置来获取一些内容。关于 MVC 依赖解析器,需要注意的重要一点是它与当前请求相关联。当当前请求结束时,请求生命周期范围与在该范围内得到解析的所有一次性对象一起被释放。这包括 WCF 服务客户端之类的东西。
最后,已发布错误的堆栈跟踪在底部如下所示:
Telerik.Reporting.Services.Engine.Rendering.RenderWithCulture(Telerik.Reporting.Services.Engine.ReportRendererArgs)
Telerik.Reporting.Services.Engine.Rendering.ThreadFunc(System.Object)
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
System.Threading.ThreadHelper.ThreadStart(System.Object)
那里有一个 ThreadStart
调用,所以这个渲染引擎似乎是 运行 在不同的线程上,它可能是从控制器启动的,但可能与请求无关一生。
我猜测发生的是:
- MVC 请求开始
- Autofac 请求生命周期开始(Autofac 依赖解析器请求生命周期)
- 报告服务已设置并开始执行
- 构造函数运行并可以解析服务客户端
- MVC 请求结束
- Autofac 请求生命周期与服务客户端一起处理
- 报告服务线程尝试使用它已解决但现在已处置的客户端
我们在 Autofac 中经常看到这种情况,人们试图在 Web 应用程序中启动后台服务或非基于请求的东西,但仍然试图将后台服务线程绑定到 web/request-related 依赖解析器和生命周期范围.
鉴于我对 Telerik 报告引擎了解不够,我不知道有哪些挂钩可以让 DI 进入它。老实说,我什至不能保证这就是问题所在,但它看起来与我在此处的其他问题中看到的这些东西完全一样。
我的推荐:
- Implement a
CommonServiceLocator
that also has the application container attached. 不要在 EmployeeProfileReportManager
或链下的任何地方使用 MVC 依赖解析器。
- 不要解析
EmployeeProfileReportManager
中的 IService.IReportEmployeeProfileService
,而是解析 Owned<IService.IReportEmployeeProfileService>
。 Owned<T>
relationship in Autofac 允许您控制处置。这很重要,因为 CommonServiceLocator 从容器中解析出来,如果您不自己控制处置,就会发生内存泄漏。
- 在您的
EmployeeProfileReportManager
中,请确保在完成后处理服务客户端。由于您使用的是 Owned<T>
,因此不会自动发生。
我在 Window Server 2012 中的 IIS 上部署程序时遇到程序抛出无法访问处置对象的问题。
根据代码,代码可以运行在我的PC开发和生产中正常但是当我部署到测试服务器时出现问题 症状是我可以 运行 在部署后的第一时间很好地编程,然后当我重新进入它抛出的页面时无法访问处理对象。
我也检查了使用 soap 重复发送请求的服务,但没有发现问题,现在在不同的 PC 和服务器上测试后它也可以 运行。
我不确定我必须对配置或服务器规范做更多的事情。 因为其他人可以 运行 拥有超过 8GB 的 ram 但在测试服务器中发现问题只有 4GB 的 ram 或者我必须编辑我的代码?
将数据源绑定到服务的代码部分
#region Employeeprofile
this.EmployeeProfileDataSource.DataMember = "GetWF_30EmployeeProfile";
this.EmployeeProfileDataSource.DataSource = typeof(THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager);
this.EmployeeProfileDataSource.Name = "EmployeeProfileDataSource";
this.EmployeeProfileDataSource.Parameters.AddRange(new Telerik.Reporting.ObjectDataSourceParameter[] {
new Telerik.Reporting.ObjectDataSourceParameter("employeeNo", typeof(string), empNo)});
report.DataSource = this.EmployeeProfileDataSource;
#endregion
#region Spouse
this.SpouseDataSource.DataMember = "GetWF_30SummaryMarriageFromBeforeApprove";
this.SpouseDataSource.DataSource = typeof(THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager);
this.SpouseDataSource.Name = "SpouseDataSource";
this.SpouseDataSource.Parameters.AddRange(new Telerik.Reporting.ObjectDataSourceParameter[] {
new Telerik.Reporting.ObjectDataSourceParameter("employeeNo", typeof(string), empNo)});
然后EmployeeProfilesReportManager 启动服务并调用
public EmployeeProfilesReportManager()
{
_service =Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<IService.IReportEmployeeProfileService>();
_logExceptionService = Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<IService.ILogException>();
}
在服务层它实现了 IDisposable
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class ReportEmployeeProfileService : IReportEmployeeProfileService, IDisposable, ICommunicationObject { }
还有代码句柄Dispose
protected virtual void Dispose(bool disposing)
{
if (disposed){
return;
}
if (disposing)
{
handle.Dispose();
}
disposed = true;
}
public void Abort()
{
_dbContext.Database.Connection.Close();
_dbContext.Dispose();
Dispose(true);
}
public void Close()
{
_dbContext.Database.Connection.Close();
_dbContext.Dispose();
Dispose(true);
}
我希望有问题的服务器可以 运行 像其他服务器一样正常。 谢谢。
使用诊断工具后我收到了这条消息
DetailID = 18
Count: 1
Type: System.ObjectDisposedException
Message: Cannot access a disposed object.
Stack:
[HelperMethodFrame]
System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable()
System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)
System.ServiceModel.Channels.ServiceChannel+CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(System.ServiceModel.Channels.ServiceChannel, System.TimeSpan)
System.ServiceModel.Channels.ServiceChannel+CallOnceManager.CallOnce(System.TimeSpan, CallOnceManager)
System.ServiceModel.Channels.ServiceChannel.EnsureOpened(System.TimeSpan)
System.ServiceModel.Channels.ServiceChannel.Call(System.String, Boolean, System.ServiceModel.Dispatcher.ProxyOperationRuntime, System.Object[], System.Object[], System.TimeSpan)
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(System.Runtime.Remoting.Messaging.IMethodCallMessage, System.ServiceModel.Dispatcher.ProxyOperationRuntime)
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(System.Runtime.Remoting.Messaging.IMessage)
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(System.Runtime.Remoting.Proxies.MessageData ByRef, Int32)
[TPMethodFrame]
THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager.GetWF_30EmployeeProfile(System.String)
[DebuggerU2MCatchHandlerFrame]
[HelperMethodFrame_PROTECTOBJ]
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].TryResolveDataSourceInstance(Boolean, System.Object ByRef, System.String ByRef)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource(Boolean)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource()
Telerik.Reporting.Processing.Data.ObjectDataEnumerable.GetEnumerator()
Telerik.Reporting.Processing.Data.ResultSetAdapter.Fill(Telerik.Reporting.Processing.Data.ResultSet, System.Collections.Generic.IEnumerable`1<Telerik.Reporting.Processing.IDataObject>)
Telerik.Reporting.Processing.Data.MultidimentionalDataProvider.Execute(Telerik.Reporting.Processing.Data.MultidimensionalQuery)
Telerik.Reporting.Processing.Report.ResolveData()
Telerik.Reporting.Processing.Report.ProcessItemCore()
Telerik.Reporting.Processing.Report.ProcessItem()
Telerik.Reporting.Processing.ReportItemBase.ProcessElement()
Telerik.Reporting.Processing.ProcessingElement.Process(Telerik.Reporting.Processing.Data.IDataMember)
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, Telerik.Reporting.Processing.IRenderingContext)
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, System.Collections.Hashtable, Telerik.Reporting.Processing.IRenderingContext)
Telerik.Reporting.Services.Engine.ReportRenderer.Render(Telerik.Reporting.Services.Engine.ReportRendererArgs)
Telerik.Reporting.Services.Engine.Rendering.RenderWithCulture(Telerik.Reporting.Services.Engine.ReportRendererArgs)
Telerik.Reporting.Services.Engine.Rendering.ThreadFunc(System.Object)
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
System.Threading.ThreadHelper.ThreadStart(System.Object)
[GCFrame]
[DebuggerU2MCatchHandlerFrame]
[ContextTransitionFrame]
[DebuggerU2MCatchHandlerFrame]
DetailID = 19
Count: 1
Type: System.ObjectDisposedException
Message: Cannot access a disposed object.
Stack:
[HelperMethodFrame]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(System.Runtime.Remoting.Proxies.MessageData ByRef, Int32)
[TPMethodFrame]
THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager.GetWF_30EmployeeProfile(System.String)
[DebuggerU2MCatchHandlerFrame]
[HelperMethodFrame_PROTECTOBJ]
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].TryResolveDataSourceInstance(Boolean, System.Object ByRef, System.String ByRef)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource(Boolean)
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource()
Telerik.Reporting.Processing.Data.ObjectDataEnumerable.GetEnumerator()
Telerik.Reporting.Processing.Data.ResultSetAdapter.Fill(Telerik.Reporting.Processing.Data.ResultSet, System.Collections.Generic.IEnumerable`1<Telerik.Reporting.Processing.IDataObject>)
Telerik.Reporting.Processing.Data.MultidimentionalDataProvider.Execute(Telerik.Reporting.Processing.Data.MultidimensionalQuery)
Telerik.Reporting.Processing.Report.ResolveData()
Telerik.Reporting.Processing.Report.ProcessItemCore()
Telerik.Reporting.Processing.Report.ProcessItem()
Telerik.Reporting.Processing.ReportItemBase.ProcessElement()
Telerik.Reporting.Processing.ProcessingElement.Process(Telerik.Reporting.Processing.Data.IDataMember)
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, Telerik.Reporting.Processing.IRenderingContext)
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, System.Collections.Hashtable, Telerik.Reporting.Processing.IRenderingContext)
Telerik.Reporting.Services.Engine.ReportRenderer.Render(Telerik.Reporting.Services.Engine.ReportRendererArgs)
Telerik.Reporting.Services.Engine.Rendering.RenderWithCulture(Telerik.Reporting.Services.Engine.ReportRendererArgs)
Telerik.Reporting.Services.Engine.Rendering.ThreadFunc(System.Object)
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
System.Threading.ThreadHelper.ThreadStart(System.Object)
[GCFrame]
[DebuggerU2MCatchHandlerFrame]
[ContextTransitionFrame]
[DebuggerU2MCatchHandlerFrame]
这是来自分析工具
Thread 24 - System ID 3404
Entry point clr!LogHelp_LogAssert+18208
Create time 5/9/2562 19:21:15
Time spent in user mode 0 Days 00:00:00.015
Time spent in kernel mode 0 Days 00:00:00.000
This thread is not fully resolved and may or may not be a problem. Further analysis of these threads may be required.
The thread has evidence of .net exceptions on the stack. Check the Previous .NET Exceptions Report (Exceptions in all .NET Thread Stacks) to view more details of the associated exception
.NET Call Stack
[[HelperMethodFrame]]
System_ServiceModel_ni!System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable()+15a
System_ServiceModel_ni!System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)+b8
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel+CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(System.ServiceModel.Channels.ServiceChannel, System.TimeSpan)+12
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel+CallOnceManager.CallOnce(System.TimeSpan, CallOnceManager)+10d
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel.EnsureOpened(System.TimeSpan)+28
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel.Call(System.String, Boolean, System.ServiceModel.Dispatcher.ProxyOperationRuntime, System.Object[], System.Object[], System.TimeSpan)+1af
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(System.Runtime.Remoting.Messaging.IMethodCallMessage, System.ServiceModel.Dispatcher.ProxyOperationRuntime)+61
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannelProxy.Invoke(System.Runtime.Remoting.Messaging.IMessage)+90
mscorlib_ni!System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(System.Runtime.Remoting.Proxies.MessageData ByRef, Int32)+114
[[TPMethodFrame] (THP.Welfare.IService.IReportEmployeeProfileService.GetWF_30EmployeeProfiles)] THP.Welfare.IService.IReportEmployeeProfileService.GetWF_30EmployeeProfiles(System.String)
THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager.GetWF_30EmployeeProfile(System.String)+59
[[DebuggerU2MCatchHandlerFrame]]
[[HelperMethodFrame_PROTECTOBJ] (System.RuntimeMethodHandle.InvokeMethod)] System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
mscorlib_ni!System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])+80
mscorlib_ni!System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)+92
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].TryResolveDataSourceInstance(Boolean, System.Object ByRef, System.String ByRef)+2ec
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource(Boolean)+2c
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource()+23
Telerik.Reporting.Processing.Data.ObjectDataEnumerable.GetEnumerator()+1d
Telerik.Reporting.Processing.Data.ResultSetAdapter.Fill(Telerik.Reporting.Processing.Data.ResultSet, System.Collections.Generic.IEnumerable`1)+249
Telerik.Reporting.Processing.Data.MultidimentionalDataProvider.Execute(Telerik.Reporting.Processing.Data.MultidimensionalQuery)+af
Telerik.Reporting.Processing.Report.ResolveData()+256
Telerik.Reporting.Processing.Report.ProcessItemCore()+68
Telerik.Reporting.Processing.Report.ProcessItem()+a0
Telerik.Reporting.Processing.ReportItemBase.ProcessElement()+27
Telerik.Reporting.Processing.ProcessingElement.Process(Telerik.Reporting.Processing.Data.IDataMember)+c4
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, Telerik.Reporting.Processing.IRenderingContext)+590
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, System.Collections.Hashtable, Telerik.Reporting.Processing.IRenderingContext)+1d0
Telerik.Reporting.Services.Engine.ReportRenderer.Render(Telerik.Reporting.Services.Engine.ReportRendererArgs)+bc
Telerik.Reporting.Services.Engine.Rendering.RenderWithCulture(Telerik.Reporting.Services.Engine.ReportRendererArgs)+51
Telerik.Reporting.Services.Engine.Rendering.ThreadFunc(System.Object)+5a
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+160
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+17
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)+52
mscorlib_ni!System.Threading.ThreadHelper.ThreadStart(System.Object)+5d
[[GCFrame]]
[[DebuggerU2MCatchHandlerFrame]]
[[ContextTransitionFrame]]
[[DebuggerU2MCatchHandlerFrame]]
Full Call Stack
KERNELBASE!RaiseException+6c
clr!LogHelp_LogAssert+16565
clr!LogHelp_LogAssert+16363
[[HelperMethodFrame]]
System_ServiceModel_ni!System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable()+15a
System_ServiceModel_ni!System.ServiceModel.Channels.CommunicationObject.Open(System.TimeSpan)+b8
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel+CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(System.ServiceModel.Channels.ServiceChannel, System.TimeSpan)+12
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel+CallOnceManager.CallOnce(System.TimeSpan, CallOnceManager)+10d
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel.EnsureOpened(System.TimeSpan)+28
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannel.Call(System.String, Boolean, System.ServiceModel.Dispatcher.ProxyOperationRuntime, System.Object[], System.Object[], System.TimeSpan)+1af
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(System.Runtime.Remoting.Messaging.IMethodCallMessage, System.ServiceModel.Dispatcher.ProxyOperationRuntime)+61
System_ServiceModel_ni!System.ServiceModel.Channels.ServiceChannelProxy.Invoke(System.Runtime.Remoting.Messaging.IMessage)+90
mscorlib_ni!System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(System.Runtime.Remoting.Proxies.MessageData ByRef, Int32)+114
clr!GetMetaDataInternalInterface+1e30e
clr!GetMetaDataPublicInterfaceFromInternal+2a8f1
clr!PreBindAssemblyEx+1b12d
[[TPMethodFrame] (THP.Welfare.IService.IReportEmployeeProfileService.GetWF_30EmployeeProfiles)] THP.Welfare.IService.IReportEmployeeProfileService.GetWF_30EmployeeProfiles(System.String)
clr!GetMetaDataInternalInterface+1e251
THP.Welfare.Reporting.ReportManager.EmployeeProfilesReportManager.GetWF_30EmployeeProfile(System.String)+59
clr+3753
clr+361c
clr!GetMetaDataInternalInterface+31766
clr!GetMetaDataInternalInterface+31550
[[DebuggerU2MCatchHandlerFrame]]
[[HelperMethodFrame_PROTECTOBJ] (System.RuntimeMethodHandle.InvokeMethod)] System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
mscorlib_ni!System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])+80
mscorlib_ni!System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)+92
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].TryResolveDataSourceInstance(Boolean, System.Object ByRef, System.String ByRef)+2ec
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource(Boolean)+2c
Telerik.Reporting.Processing.Data.ObjectDataProviderBase`1[[System.__Canon, mscorlib]].ResolveDataSource()+23
Telerik.Reporting.Processing.Data.ObjectDataEnumerable.GetEnumerator()+1d
Telerik.Reporting.Processing.Data.ResultSetAdapter.Fill(Telerik.Reporting.Processing.Data.ResultSet, System.Collections.Generic.IEnumerable`1<Telerik.Reporting.Processing.IDataObject>)+249
Telerik.Reporting.Processing.Data.MultidimentionalDataProvider.Execute(Telerik.Reporting.Processing.Data.MultidimensionalQuery)+af
Telerik.Reporting.Processing.Report.ResolveData()+256
Telerik.Reporting.Processing.Report.ProcessItemCore()+68
Telerik.Reporting.Processing.Report.ProcessItem()+a0
Telerik.Reporting.Processing.ReportItemBase.ProcessElement()+27
Telerik.Reporting.Processing.ProcessingElement.Process(Telerik.Reporting.Processing.Data.IDataMember)+c4
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, Telerik.Reporting.Processing.IRenderingContext)+590
Telerik.Reporting.Processing.ReportProcessor.ProcessReport(Telerik.Reporting.ReportSource, System.Collections.Hashtable, Telerik.Reporting.Processing.IRenderingContext)+1d0
Telerik.Reporting.Services.Engine.ReportRenderer.Render(Telerik.Reporting.Services.Engine.ReportRendererArgs)+bc
Telerik.Reporting.Services.Engine.Rendering.RenderWithCulture(Telerik.Reporting.Services.Engine.ReportRendererArgs)+51
Telerik.Reporting.Services.Engine.Rendering.ThreadFunc(System.Object)+5a
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+160
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+17
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)+52
mscorlib_ni!System.Threading.ThreadHelper.ThreadStart(System.Object)+5d
clr+3753
clr+361c
clr+44d3
clr!TranslateSecurityAttributes+11f684
[[GCFrame]]
clr+6810
clr+67c0
clr+6705
[[DebuggerU2MCatchHandlerFrame]]
clr+71b0
clr+725e
[[ContextTransitionFrame]]
clr+7193
clr+67c0
clr+6705
[[DebuggerU2MCatchHandlerFrame]]
clr+6947
clr!TranslateSecurityAttributes+11f29f
clr!LogHelp_LogAssert+1827e
kernel32!BaseThreadInitThunk+22
ntdll!RtlUserThreadStart+34
Exception Information
In w3wp__ThaihealthWelfare__PID__2376__Date__09_05_2019__Time_07_21_19PM__859__First Chance System.ObjectDisposedException.dmp the assembly instruction at KERNELBASE!RaiseException in C:\Windows\System32\KERNELBASE.dll from Microsoft Corporation has caused a CLR Exception on thread 24 with the following error information:
Type: System.ObjectDisposedException
Message: Cannot access a disposed object.
This exception originated from System_ServiceModel_ni!System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable().
Module Information
Image Name: C:\Windows\assembly\NativeImages_v4.0.30319_64\System.ServiceModeld239193fcf663b211916bd928cfaeb1\System.ServiceModel.ni.dll Symbol Type: None
Base address: 0x00000000`00005a4d Time Stamp: Fri Nov 06 10:20:22 2015
Checksum: 0x00000000`00000000 Comments: Flavor=Retail
COM DLL: False Company Name: Microsoft Corporation
ISAPIExtension: False File Description: System.ServiceModel.dll
ISAPIFilter: False File Version: 4.6.1055.0 built by: NETFXREL2
Managed DLL: True Internal Name: System.ServiceModel.dll
VB DLL: False Legal Copyright: ? Microsoft Corporation. All rights reserved.
Loaded Image Name: System.ServiceModel.ni.dll Legal Trademarks:
Mapped Image Name: Original filename: System.ServiceModel.dll
Module name: System_ServiceModel_ni Private Build: DDBLD400
Single Threaded: False Product Name: Microsoft? .NET Framework
Module Size: 23.41 MBytes Product Version: 4.6.1055.0
Symbol File Name: System.ServiceModel.ni.dll Special Build: &
after following the answer now I can solve the problem with edit my code as
#region Field
private readonly Owned<IService.IReportEmployeeProfileService> _service;
private readonly Owned<IService.ILogException> _logExceptionService;
#endregion
#region Constructor
public EmployeeProfilesReportManager()
{
_service = Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<Owned<IService.IReportEmployeeProfileService>>();
_logExceptionService = Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<Owned<IService.ILogException>>();
}
#endregion
并且在我这样调用服务的所有方法中
public List<SummaryMarriageInfoBeforeApproveModel> GetSummaryMarriageFromBeforeApprove(string employeeNo)
{
var result = _service.Value.GetSummaryMarriageFromBeforeApprove(employeeNo);
_service.Dispose();
_logExceptionService.Dispose();
return result;
}
次要免责声明:我知道 Autofac,但我从未使用过 Telerik 报告服务引擎。但我能猜到发生了什么。
您的情况似乎是 threading/race。
在评论中,您注意到[为了便于阅读而格式化]:
in in startup.cs have create channel as singleton
builder.Register(c => new ChannelFactory<T>("DefaultService")).SingleInstance();
builder.Register(c => c.Resolve<ChannelFactory<T>>().CreateChannel()).UseWcfSafeRelease();
我假设 <T>
是您实际使用的缩写。
我也看到了这个片段:
public EmployeeProfilesReportManager()
{
_service =Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<IService.IReportEmployeeProfileService>();
_logExceptionService = Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<IService.ILogException>();
}
报表管理器正在使用 MVC 依赖项解析器上的服务位置来获取一些内容。关于 MVC 依赖解析器,需要注意的重要一点是它与当前请求相关联。当当前请求结束时,请求生命周期范围与在该范围内得到解析的所有一次性对象一起被释放。这包括 WCF 服务客户端之类的东西。
最后,已发布错误的堆栈跟踪在底部如下所示:
Telerik.Reporting.Services.Engine.Rendering.RenderWithCulture(Telerik.Reporting.Services.Engine.ReportRendererArgs)
Telerik.Reporting.Services.Engine.Rendering.ThreadFunc(System.Object)
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
System.Threading.ThreadHelper.ThreadStart(System.Object)
那里有一个 ThreadStart
调用,所以这个渲染引擎似乎是 运行 在不同的线程上,它可能是从控制器启动的,但可能与请求无关一生。
我猜测发生的是:
- MVC 请求开始
- Autofac 请求生命周期开始(Autofac 依赖解析器请求生命周期)
- 报告服务已设置并开始执行
- 构造函数运行并可以解析服务客户端
- MVC 请求结束
- Autofac 请求生命周期与服务客户端一起处理
- 报告服务线程尝试使用它已解决但现在已处置的客户端
我们在 Autofac 中经常看到这种情况,人们试图在 Web 应用程序中启动后台服务或非基于请求的东西,但仍然试图将后台服务线程绑定到 web/request-related 依赖解析器和生命周期范围.
鉴于我对 Telerik 报告引擎了解不够,我不知道有哪些挂钩可以让 DI 进入它。老实说,我什至不能保证这就是问题所在,但它看起来与我在此处的其他问题中看到的这些东西完全一样。
我的推荐:
- Implement a
CommonServiceLocator
that also has the application container attached. 不要在EmployeeProfileReportManager
或链下的任何地方使用 MVC 依赖解析器。 - 不要解析
EmployeeProfileReportManager
中的IService.IReportEmployeeProfileService
,而是解析Owned<IService.IReportEmployeeProfileService>
。Owned<T>
relationship in Autofac 允许您控制处置。这很重要,因为 CommonServiceLocator 从容器中解析出来,如果您不自己控制处置,就会发生内存泄漏。 - 在您的
EmployeeProfileReportManager
中,请确保在完成后处理服务客户端。由于您使用的是Owned<T>
,因此不会自动发生。