Exception.SerializeObjectState 事件

定義

警告

BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。

protected:
 event EventHandler<System::Runtime::Serialization::SafeSerializationEventArgs ^> ^ SerializeObjectState;
protected event EventHandler<System.Runtime.Serialization.SafeSerializationEventArgs>? SerializeObjectState;
[System.Obsolete("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId="SYSLIB0011", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected event EventHandler<System.Runtime.Serialization.SafeSerializationEventArgs>? SerializeObjectState;
protected event EventHandler<System.Runtime.Serialization.SafeSerializationEventArgs> SerializeObjectState;
member this.SerializeObjectState : EventHandler<System.Runtime.Serialization.SafeSerializationEventArgs> 
[<System.Obsolete("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId="SYSLIB0011", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
member this.SerializeObjectState : EventHandler<System.Runtime.Serialization.SafeSerializationEventArgs> 
Protected Custom Event SerializeObjectState As EventHandler(Of SafeSerializationEventArgs) 

事件類型

屬性

備註

例外狀況狀態物件會實作 ISafeSerializationData 介面。

SerializeObjectState訂閱事件時,例外狀況會還原序列化,並建立為空的例外狀況。 例外狀況的建構函式未執行,而且例外狀況狀態也會還原序列化。 CompleteDeserialization然後會通知例外狀況狀態物件的回呼方法,以便將還原序列化的資料推送至空的例外狀況。

事件 SerializeObjectState 可讓透明例外狀況類型序列化和還原序列化例外狀況資料。 透明程式碼可以在它正在操作的許可權集範圍內執行命令,但無法執行、呼叫、衍生自或包含重要程式碼。

SerializeObjectState如果未訂閱事件,則會使用 Exception 建構函式如往常般進行還原序列化。

一般而言,例外狀況的建構函式中會加入 事件的處理常式 SerializeObjectState ,以提供其序列化。 但是,因為事件處理常式執行時 SerializeObjectState 不會執行建構函式,因此當您嘗試還原序列化例外狀況時,序列化還原序列化例外狀況可能會擲 SerializationException 回例外狀況。 若要避免這種情況,您也應該在 方法中 ISafeSerializationData.CompleteDeserialization 新增 事件的處理常式 SerializeObjectState 。 如需圖例,請參閱一節。

給繼承者的注意事項

如果訂閱及使用這個事件,繼承階層中後續的所有衍生型別都必須實作相同的序列化機制。

適用於