如何修复'System.ServiceModel.ExceptionDetail'未标记为可序列化

时间:2012-05-24 08:42:37

标签: c# asp.net wcf

我有一个由ASP .Net网站调用的WCF Web服务。在我的Web方法中,我故意不捕获异常,因为我希望它们由客户端网站处理。 Web服务纯粹是一个内部应用程序,我希望它的行为类似于标准库,它希望调用者处理异常。我在服务web.config中有includeExceptionDetailInFaults =“true”。当我的服务抛出异常时,我收到此错误:

Log Name:      Application
Source:        ASP.NET 2.0.50727.0
Date:          24/05/2012 09:13:52
Event ID:      1334
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Description:
An unhandled exception occurred and the process was terminated.

Application ID: DefaultDomain

Process ID: 2628

Exception: System.Runtime.Serialization.SerializationException

Message: Type 'System.ServiceModel.ExceptionDetail' in Assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

StackTrace:    at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
   at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
   at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeObject(Object obj, MemoryStream stm)
   at System.AppDomain.Serialize(Object o)
   at System.AppDomain.MarshalObject(Object o)

如何修复此问题,以便我的客户端能够捕获服务引发的异常?

1 个答案:

答案 0 :(得分:0)

我找到了问题的原因 - 我的Web服务中的工作线程(System.Threading.ThreadPool.QueueUserWorkItem)中抛出了异常,因此当然没有被处理。通过添加异常处理程序并记录到工作线程来修复。