2011-01-12 2 views
1

オブジェクトを逆シリアル化している場合があります。例外は私には本質的に意味がありませんが、デバッグをリダイレクトするためにどこが失敗したのかを判断する方法が必要です。オブジェクトグラフ内のどのオブジェクトがSerializationExceptionを引き起こしたかを特定するにはどうすればいいですか?

これは例外である:

System.Runtime.Serialization.SerializationException は、メッセージ= " オブジェクトの201326592」のいかなるマップ。" キャッチされませんでした
ソース: "mscorlib" StackTrace: at System.Runtime.Serialization.Formatters.Binary._ BinaryParser.ReadObject() at System.Runtime.Serialization.Formatters.Binary。 System.Runtime.Serialization.FormattersでSystem.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(isCrossAppDomain、IMethodCallMessage methodCallMessage HeaderHandler ハンドラ、__BinaryParser serParser、 ブールはFCheck、ブール )で _BinaryParser.Run() アナで.Binary.BinaryFormatter.Deserialize(ストリーム serializationStream、HeaderHandler ハンドラ、ブールはFCheck、ブール isCrossAppDomain、IMethodCallMessage methodCallMessage)System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(ストリーム serializationStream)で lytics.ReportInstance.Open(ストリーム TStreamに、ブール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 

おかげで、 ブライアン

答えて

1

あなたが見ている例外がスローされたときに、オブジェクトの「IDをマップ」 - 整数で、以前の型定義を参照する必要があり、その種類を特定しますストリーム - ではありませんタイプのテーブルにあります。

通常、バイトストリームが転送中にマングリングされないか、フォーマッタインスタンスが不適切に再利用されない限り、これは起こりません。

BinaryFormatterは、すでに処理されたすべてのデータを追跡し、以前に書き込まれた型とオブジェクト(逆シリアル化時)の逆参照を解決するために以前読み込まれたデータを使用することができます。

+0

それであなたはどのように修正しますか? – hofnarwillie

+0

@hofnarwillie根本的な原因によって異なります。 –

関連する問題