我正在反序列化对象,并且在某些情况下它可以正常工作,但是在其他情况下它会失败。这个例外对我来说基本上没有意义,但是必须有一种方法来确定它到底发生了什么,所以我重定向了我的调试。如何确定对象图中的哪个对象导致SerializationException
这是例外:
System.Runtime.Serialization.SerializationException 被抓消息= “否地图为 对象 '201326592'。”
Source =“mscorlib”StackTrace: at System.Runtime.Serialization.Formatters.Binary._ BinaryParser.ReadObject() at System.Runtime.Serialization.Formatters.Binary。 _BinaryParser.Run() 在System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler 处理程序,__BinaryParser serParser, 布尔FCHECK,布尔 isCrossAppDomain,IMethodCallMessage methodCallMessage) 在System.Runtime.Serialization.Formatters .Binary.BinaryFormatter.Deserialize(流 serializationStream,HeaderHandler 处理程序,布尔FCHECK,布尔 isCrossAppDomain,IMethodCallMessage methodCallMessage) 在System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(流 serializationStream) 在安娜lytics.ReportInstance.Open(流 T流,布尔OpenResults)在 C:\用户...路径... \ File.vb:线 149的InnerException:
而这是源代码,其中它被困:
Public Shared Function Open(ByVal tStream As IO.Stream, Optional ByVal OpenResults As Boolean = False) As ReportInstance
Dim tFormatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = PluginSerializationBinder.CreateSerializer()
Dim tInstance As ReportInstance
Try
If OpenResults Then 'case which always fails
'open the entire report
If System.Diagnostics.Debugger.IsAttached Then
Console.WriteLine("Deserializing: report results")
End If
tInstance = tFormatter.Deserialize(tStream) 'throws exception here
Return tInstance
Else 'case which always works (only deserializing part of the object)
'just open the stub
If System.Diagnostics.Debugger.IsAttached Then
Console.WriteLine("Deserializing: report instance")
End If
Dim tInput As New IO.BinaryReader(tStream)
Dim tLength As Long = tInput.ReadInt64()
Dim tBytes() As Byte = tInput.ReadBytes(tLength)
Dim tMem As New IO.MemoryStream(tBytes)
tInstance = tFormatter.Deserialize(tMem)
Return tInstance
End If
Catch ex As Exception
If (ex.Message.Contains("blah")) Then
Throw New UnsupportedException(ex.Message)
Else
Throw 'trapped here
End If
End Try
End Function
感谢, 布赖恩
那么你如何解决它? – hofnarwillie 2012-11-28 11:56:58