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
- SecurityChannelFaultConverter.cs
- SecurityElement.cs
- App.cs
- FlowDocumentPage.cs
- ObjectIDGenerator.cs
- CapabilitiesAssignment.cs
- BitmapEffectDrawing.cs
- UnsafeNativeMethods.cs
- Soap.cs
- FilteredAttributeCollection.cs
- Serialization.cs
- RegexWriter.cs
- TdsParserStateObject.cs
- ProtocolException.cs
- CorrelationTokenTypeConvertor.cs
- StatusBarItemAutomationPeer.cs
- IDReferencePropertyAttribute.cs
- RenameRuleObjectDialog.Designer.cs
- TagPrefixInfo.cs
- FixedSOMTableCell.cs
- ValueExpressions.cs
- SelectionWordBreaker.cs
- ResourceKey.cs
- WebServiceEnumData.cs
- GeneralTransformGroup.cs
- DataGridViewSelectedRowCollection.cs
- BackgroundWorker.cs
- TableLayoutSettings.cs
- BitmapCodecInfo.cs
- AliasGenerator.cs
- GridViewCancelEditEventArgs.cs
- ListItemConverter.cs
- nulltextcontainer.cs
- HttpContextWrapper.cs
- LinkUtilities.cs
- Invariant.cs
- RewritingValidator.cs
- updateconfighost.cs
- IntSecurity.cs
- DependencyObjectProvider.cs
- RichTextBox.cs
- PropertyMetadata.cs
- PersonalizationDictionary.cs
- DataObject.cs
- SecurityPolicySection.cs
- ManifestResourceInfo.cs
- ToolZone.cs
- SessionParameter.cs
- SafeNativeMethods.cs
- infer.cs
- GenerateScriptTypeAttribute.cs
- ToolStripAdornerWindowService.cs
- EntityReference.cs
- FollowerQueueCreator.cs
- Block.cs
- ScalarType.cs
- SecurityCapabilities.cs
- AssociationTypeEmitter.cs
- XmlDataContract.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- PropertyFilterAttribute.cs
- KeyPullup.cs
- WindowsRichEdit.cs
- TileBrush.cs
- SettingsAttributes.cs
- TextBoxRenderer.cs
- StrokeDescriptor.cs
- ForeignKeyConstraint.cs
- UIElement3D.cs
- X509CertificateValidationMode.cs
- DateTimeUtil.cs
- SapiGrammar.cs
- DocumentPage.cs
- CompilerInfo.cs
- MinMaxParagraphWidth.cs
- XmlNullResolver.cs
- OptimizedTemplateContent.cs
- Scripts.cs
- DataGridColumnHeadersPresenter.cs
- PersianCalendar.cs
- ConfigurationProperty.cs
- NonBatchDirectoryCompiler.cs
- DurationConverter.cs
- HtmlUtf8RawTextWriter.cs
- ProxyManager.cs
- MsdtcClusterUtils.cs
- AuthenticationException.cs
- _NativeSSPI.cs
- XmlValueConverter.cs
- Synchronization.cs
- ByteStream.cs
- PropertySourceInfo.cs
- C14NUtil.cs
- XmlReaderSettings.cs
- HttpPostProtocolImporter.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- Popup.cs
- UseLicense.cs
- DataColumnPropertyDescriptor.cs
- SQLInt32.cs