/********************************************************************++ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System.Runtime.Serialization; #if !CORECLR using System.Security.Permissions; #else // Use stub for SerializableAttribute. using Microsoft.PowerShell.CoreClr.Stubs; #endif namespace System.Management.Automation { /// /// This is a wrapper for exception class /// /// which provides additional information via /// . /// /// /// Instances of this exception class are usually generated by the /// Monad Engine. It is unusual for code outside the Monad Engine /// to create an instance of this class. /// [Serializable] public class PSObjectDisposedException : ObjectDisposedException, IContainsErrorRecord { #region ctor /// /// Initializes a new instance of the PSObjectDisposedException class. /// /// /// constructed object /// /// Per MSDN, the parameter is objectName and not message. /// I confirm this experimentally as well. /// Also note that there is no parameterless constructor. /// public PSObjectDisposedException(string objectName) : base(objectName) { } /// /// Initializes a new instance of the PSObjectDisposedException class. /// /// /// /// constructed object public PSObjectDisposedException(string objectName, string message) : base(objectName, message) { } /// /// Initializes a new instance of the PSObjectDisposedException class. /// /// /// /// constructed object public PSObjectDisposedException(string message, Exception innerException) : base(message, innerException) { } #region Serialization #if !CORECLR // ObjectDisposedException Has No Serialization In CoreCLR /// /// Initializes a new instance of the PSObjectDisposedException class /// using data serialized via /// /// /// serialization information /// streaming context /// constructed object protected PSObjectDisposedException(SerializationInfo info, StreamingContext context) : base(info, context) { _errorId = info.GetString("ErrorId"); } /// /// Serializer for /// /// serialization information /// streaming context [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { throw new PSArgumentNullException("info"); } base.GetObjectData(info, context); info.AddValue("ErrorId", _errorId); } #endif #endregion Serialization #endregion ctor /// /// Additional information about the error /// /// /// /// Note that ErrorRecord.Exception is /// . /// public ErrorRecord ErrorRecord { get { if (null == _errorRecord) { _errorRecord = new ErrorRecord( new ParentContainsErrorRecordException(this), _errorId, ErrorCategory.InvalidOperation, null); } return _errorRecord; } } private ErrorRecord _errorRecord; private string _errorId = "ObjectDisposed"; } // PSObjectDisposedException } // System.Management.Automation