Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
MshObjectDisposedException.cs104 linesDownload Raw Back to utils
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Runtime.Serialization;5 6namespace System.Management.Automation7{8    /// <summary>9    /// This is a wrapper for exception class10    /// <see cref="System.ObjectDisposedException"/>11    /// which provides additional information via12    /// <see cref="System.Management.Automation.IContainsErrorRecord"/>.13    /// </summary>14    /// <remarks>15    /// Instances of this exception class are usually generated by the16    /// PowerShell Engine.  It is unusual for code outside the PowerShell Engine17    /// to create an instance of this class.18    /// </remarks>19    public class PSObjectDisposedException20            : ObjectDisposedException, IContainsErrorRecord21    {22        #region ctor23        /// <summary>24        /// Initializes a new instance of the PSObjectDisposedException class.25        /// </summary>26        /// <param name="objectName"></param>27        /// <returns>Constructed object.</returns>28        /// <remarks>29        /// Per MSDN, the parameter is objectName and not message.30        /// I confirm this experimentally as well.31        /// Also note that there is no parameterless constructor.32        /// </remarks>33        public PSObjectDisposedException(string objectName)34            : base(objectName)35        {36        }37 38        /// <summary>39        /// Initializes a new instance of the PSObjectDisposedException class.40        /// </summary>41        /// <param name="objectName"></param>42        /// <param name="message"></param>43        /// <returns>Constructed object.</returns>44        public PSObjectDisposedException(string objectName, string message)45                : base(objectName, message)46        {47        }48 49        /// <summary>50        /// Initializes a new instance of the PSObjectDisposedException class.51        /// </summary>52        /// <param name="message"></param>53        /// <param name="innerException"></param>54        /// <returns>Constructed object.</returns>55        public PSObjectDisposedException(string message, Exception innerException)56            : base(message, innerException)57        {58        }59 60        #region Serialization61        /// <summary>62        /// Initializes a new instance of the PSObjectDisposedException class63        /// using data serialized via64        /// <see cref="System.Runtime.Serialization.ISerializable"/>65        /// </summary>66        /// <param name="info">Serialization information.</param>67        /// <param name="context">Streaming context.</param>68        /// <returns>Constructed object.</returns>69        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]70        protected PSObjectDisposedException(SerializationInfo info, StreamingContext context) : base(info, context)71        {72            throw new NotSupportedException();73        }74 75        #endregion Serialization76        #endregion ctor77 78        /// <summary>79        /// Additional information about the error.80        /// </summary>81        /// <value></value>82        /// <remarks>83        /// Note that ErrorRecord.Exception is84        /// <see cref="System.Management.Automation.ParentContainsErrorRecordException"/>.85        /// </remarks>86        public ErrorRecord ErrorRecord87        {88            get89            {90                _errorRecord ??= new ErrorRecord(91                    new ParentContainsErrorRecordException(this),92                    _errorId,93                    ErrorCategory.InvalidOperation,94                    null);95 96                return _errorRecord;97            }98        }99 100        private ErrorRecord _errorRecord;101        private readonly string _errorId = "ObjectDisposed";102    }103}104