Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
MshConsoleLoadException.cs117 linesDownload Raw Back to config
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Collections.ObjectModel;5using System.Runtime.Serialization;6using System.Security.Permissions;7using System.Text;8 9namespace System.Management.Automation.Runspaces10{11    /// <summary>12    /// Defines exception thrown when a PSSnapin was not able to load into current runspace.13    /// </summary>14    /// <!--15    /// Implementation of PSConsoleLoadException requires it to16    ///     1. Implement IContainsErrorRecord,17    ///     2. ISerializable18    ///19    /// Basic information for this exception includes,20    ///     1. PSSnapin name21    ///     2. Inner exception.22    /// -->23    public class PSConsoleLoadException : SystemException, IContainsErrorRecord24    {25        /// <summary>26        /// Initiate an instance of PSConsoleLoadException.27        /// </summary>28        public PSConsoleLoadException() : base()29        {30        }31 32        /// <summary>33        /// Initiate an instance of PSConsoleLoadException.34        /// </summary>35        /// <param name="message">Error message.</param>36        public PSConsoleLoadException(string message)37            : base(message)38        {39        }40 41        /// <summary>42        /// Initiate an instance of PSConsoleLoadException.43        /// </summary>44        /// <param name="message">Error message.</param>45        /// <param name="innerException">Inner exception.</param>46        public PSConsoleLoadException(string message, Exception innerException)47            : base(message, innerException)48        {49        }50 51        private ErrorRecord _errorRecord;52 53        /// <summary>54        /// Gets error record embedded in this exception.55        /// </summary>56        /// <!--57        /// This property is required as part of IErrorRecordContainer58        /// interface.59        /// -->60        public ErrorRecord ErrorRecord61        {62            get63            {64                return _errorRecord;65            }66        }67 68        /// <summary>69        /// Create the internal error record.70        /// The ErrorRecord created will be stored in the _errorRecord member.71        /// </summary>72        private void CreateErrorRecord()73        {74            StringBuilder sb = new StringBuilder();75 76            if (PSSnapInExceptions != null)77            {78                foreach (PSSnapInException e in PSSnapInExceptions)79                {80                    sb.Append('\n');81                    sb.Append(e.Message);82                }83            }84 85            _errorRecord = new ErrorRecord(new ParentContainsErrorRecordException(this), "ConsoleLoadFailure", ErrorCategory.ResourceUnavailable, null);86        }87 88        private readonly Collection<PSSnapInException> _PSSnapInExceptions = new Collection<PSSnapInException>();89 90        internal Collection<PSSnapInException> PSSnapInExceptions91        {92            get93            {94                return _PSSnapInExceptions;95            }96        }97 98        /// <summary>99        /// Gets message for this exception.100        /// </summary>101        public override string Message102        {103            get104            {105                if (_errorRecord != null)106                {107                    return _errorRecord.ToString();108                }109                else110                {111                    return base.Message;112                }113            }114        }115    }116}117