Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Messaging / System / Messaging / MessageQueueException.cs / 1305376 / MessageQueueException.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Messaging { using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Diagnostics; using System; using System.Text; using System.Messaging.Interop; using System.ComponentModel; using Microsoft.Win32; using System.Globalization; ////// /// [Serializable] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")] public class MessageQueueException : ExternalException, ISerializable { private readonly int nativeErrorCode; ////// Is thrown if a Microsoft Message /// Queue Server (MSMQ) internal error occurs. /// ////// internal MessageQueueException(int error) { nativeErrorCode = error; } /// /// protected MessageQueueException(SerializationInfo info, StreamingContext context) : base (info, context) { nativeErrorCode = info.GetInt32("NativeErrorCode"); } /// /// /// public MessageQueueErrorCode MessageQueueErrorCode { get { return (MessageQueueErrorCode)nativeErrorCode; } } ///[To be supplied.] ////// /// public override string Message { get { try { return Res.GetString(Convert.ToString(nativeErrorCode, 16).ToUpper(CultureInfo.InvariantCulture)); } catch { return GetUnknownErrorMessage(nativeErrorCode); } } } private static string GetUnknownErrorMessage(int error) { //get the system error message... string errorMsg = ""; StringBuilder sb = new StringBuilder(256); int result = SafeNativeMethods.FormatMessage(SafeNativeMethods.FORMAT_MESSAGE_IGNORE_INSERTS | SafeNativeMethods.FORMAT_MESSAGE_FROM_SYSTEM | SafeNativeMethods.FORMAT_MESSAGE_ARGUMENT_ARRAY, IntPtr.Zero, error, 0, sb, sb.Capacity + 1, IntPtr.Zero); if (result != 0) { int i = sb.Length; while (i > 0) { char ch = sb[i - 1]; if (ch > 32 && ch != '.') break; i--; } errorMsg = sb.ToString(0, i); } else { errorMsg =Res.GetString("UnknownError", Convert.ToString(error, 16)); } return errorMsg; } ///[To be supplied.] ///[System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { throw new ArgumentNullException("info"); } info.AddValue("NativeErrorCode", nativeErrorCode); base.GetObjectData(info, context); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Messaging { using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Diagnostics; using System; using System.Text; using System.Messaging.Interop; using System.ComponentModel; using Microsoft.Win32; using System.Globalization; ////// /// [Serializable] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")] public class MessageQueueException : ExternalException, ISerializable { private readonly int nativeErrorCode; ////// Is thrown if a Microsoft Message /// Queue Server (MSMQ) internal error occurs. /// ////// internal MessageQueueException(int error) { nativeErrorCode = error; } /// /// protected MessageQueueException(SerializationInfo info, StreamingContext context) : base (info, context) { nativeErrorCode = info.GetInt32("NativeErrorCode"); } /// /// /// public MessageQueueErrorCode MessageQueueErrorCode { get { return (MessageQueueErrorCode)nativeErrorCode; } } ///[To be supplied.] ////// /// public override string Message { get { try { return Res.GetString(Convert.ToString(nativeErrorCode, 16).ToUpper(CultureInfo.InvariantCulture)); } catch { return GetUnknownErrorMessage(nativeErrorCode); } } } private static string GetUnknownErrorMessage(int error) { //get the system error message... string errorMsg = ""; StringBuilder sb = new StringBuilder(256); int result = SafeNativeMethods.FormatMessage(SafeNativeMethods.FORMAT_MESSAGE_IGNORE_INSERTS | SafeNativeMethods.FORMAT_MESSAGE_FROM_SYSTEM | SafeNativeMethods.FORMAT_MESSAGE_ARGUMENT_ARRAY, IntPtr.Zero, error, 0, sb, sb.Capacity + 1, IntPtr.Zero); if (result != 0) { int i = sb.Length; while (i > 0) { char ch = sb[i - 1]; if (ch > 32 && ch != '.') break; i--; } errorMsg = sb.ToString(0, i); } else { errorMsg =Res.GetString("UnknownError", Convert.ToString(error, 16)); } return errorMsg; } ///[To be supplied.] ///[System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { throw new ArgumentNullException("info"); } info.AddValue("NativeErrorCode", nativeErrorCode); base.GetObjectData(info, context); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ToolStripSeparator.cs
- SchemaHelper.cs
- Emitter.cs
- XmlSchemaAttribute.cs
- HandlerMappingMemo.cs
- DistinctQueryOperator.cs
- ListBase.cs
- KeySplineConverter.cs
- DaylightTime.cs
- FrameworkObject.cs
- SymbolType.cs
- TreeNodeStyleCollection.cs
- CustomAttributeSerializer.cs
- CanonicalXml.cs
- IncrementalCompileAnalyzer.cs
- HandleCollector.cs
- Transform3DCollection.cs
- _ConnectStream.cs
- InternalConfigConfigurationFactory.cs
- OutputScope.cs
- DependencyObjectType.cs
- mongolianshape.cs
- TreeWalker.cs
- ProcessModule.cs
- DataGridTableCollection.cs
- DefaultSerializationProviderAttribute.cs
- DescendantQuery.cs
- TextTreeExtractElementUndoUnit.cs
- SystemResources.cs
- ProfilePropertyNameValidator.cs
- PrimaryKeyTypeConverter.cs
- URLMembershipCondition.cs
- ArraySegment.cs
- TaiwanCalendar.cs
- ApplicationDirectoryMembershipCondition.cs
- HandlerWithFactory.cs
- CornerRadiusConverter.cs
- WebPartEditorApplyVerb.cs
- DataGridCommandEventArgs.cs
- OperatorExpressions.cs
- ModuleConfigurationInfo.cs
- StateManager.cs
- StateManagedCollection.cs
- Durable.cs
- CellPartitioner.cs
- AuthorizationBehavior.cs
- ModuleElement.cs
- _HeaderInfoTable.cs
- EntitySqlQueryCacheKey.cs
- PolicyVersion.cs
- OpenFileDialog.cs
- Misc.cs
- WebPartEditorApplyVerb.cs
- RelationshipManager.cs
- TextEditorCharacters.cs
- EnumType.cs
- EntityCommandCompilationException.cs
- TdsParserSessionPool.cs
- XmlException.cs
- BitmapPalettes.cs
- DiscreteKeyFrames.cs
- XmlTextReaderImpl.cs
- ISFTagAndGuidCache.cs
- ListDictionary.cs
- Event.cs
- EventLogPermissionEntry.cs
- UserPreferenceChangingEventArgs.cs
- InputManager.cs
- ImageCodecInfoPrivate.cs
- Literal.cs
- MetabaseSettingsIis7.cs
- ZipFileInfo.cs
- X509Certificate2Collection.cs
- CookieProtection.cs
- Track.cs
- OleDbReferenceCollection.cs
- XmlSchemaNotation.cs
- ParserExtension.cs
- AnnotationHighlightLayer.cs
- EntityDescriptor.cs
- WindowsAuthenticationEventArgs.cs
- PeerApplication.cs
- MinimizableAttributeTypeConverter.cs
- ImageBrush.cs
- SchemaLookupTable.cs
- KeyedHashAlgorithm.cs
- UserControl.cs
- safemediahandle.cs
- MissingSatelliteAssemblyException.cs
- DataGridRowHeaderAutomationPeer.cs
- DllNotFoundException.cs
- MailAddress.cs
- MobileResource.cs
- RuleProcessor.cs
- ListViewItemMouseHoverEvent.cs
- NetTcpSecurity.cs
- TemplateNameScope.cs
- ReflectEventDescriptor.cs
- DispatcherExceptionFilterEventArgs.cs
- TagPrefixAttribute.cs