Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / SMDiagnostics / System / ServiceModel / Diagnostics / AssertUtility.cs / 1305376 / AssertUtility.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- // This class needs to function even if it was built retail. That is, a debug caller calling against a retail // SMDiagnostics should still have asserts fire. To achieve that, we need to define DEBUG here. // We do not do the registry override in retail SMDiagnostics because that would require shipping a test hook. We // do not generally ship test hooks today. #if DEBUG #define DEBUG_FOR_REALS #else #define DEBUG #endif namespace System.ServiceModel.Diagnostics { using System; using System.Runtime; using System.Runtime.Interop; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; using Microsoft.Win32; static class AssertUtility { #if DEBUG_FOR_REALS const string WinFXRegistryKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP"; const string WcfRegistryKey = AssertUtility.WinFXRegistryKey + @"\CDF\v4.0\Debug"; const string AssertsFailFastName = "AssertsFailFast"; #endif [Obsolete("For SMDiagnostics.dll use only. Call DiagnosticUtility.DebugAssert instead")] [SuppressMessage(FxCop.Category.ReliabilityBasic, FxCop.Rule.InvariantAssertRule, Justification = "Assert implementation")] internal static void DebugAssertCore(string message) { try { #if DEBUG_FOR_REALS string debugMessage = "WCF Assert fired! --> " + message + "\r\n"; if (Debugger.IsAttached) { Debugger.Log(0, Debugger.DefaultCategory, debugMessage); Debugger.Break(); } if (UnsafeNativeMethods.IsDebuggerPresent()) { UnsafeNativeMethods.OutputDebugString(debugMessage); UnsafeNativeMethods.DebugBreak(); } // This can be switched to just FailFast (e.g. for the stress lab). RegistryKey key = Registry.LocalMachine.OpenSubKey(AssertUtility.WcfRegistryKey); if (key != null) { object value; using (key) { value = key.GetValue(AssertUtility.AssertsFailFastName); } if (value != null && typeof(int).IsAssignableFrom(value.GetType()) && ((int) value) != 0) { try { if (ExceptionUtility.mainInstance != null) { #pragma warning disable 618 ExceptionUtility.mainInstance.TraceFailFast(message); } else { ExceptionUtility.TraceFailFast(message, new EventLogger("System.ServiceModel", null)); } #pragma warning restore 618 } finally { Environment.FailFast(message); } } } } catch (Exception exception) { message = string.Concat("Exception during assert! [", exception.GetType().Name, ": ", exception.Message, "] --> ", message); throw; #endif } finally { Debug.Assert(false, message); } } // For use within SMDiagnostics. [Conditional("DEBUG")] [Obsolete("For SMDiagnostics.dll use only. Call DiagnosticUtility.DebugAssert instead")] internal static void DebugAssert(bool condition, string message) { if (!condition) { DebugAssert(message); } } [MethodImpl(MethodImplOptions.NoInlining)] [Conditional("DEBUG")] [Obsolete("For SMDiagnostics.dll use only. Call DiagnosticUtility.DebugAssert instead")] internal static void DebugAssert(string message) { DebugAssertCore(message); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- // This class needs to function even if it was built retail. That is, a debug caller calling against a retail // SMDiagnostics should still have asserts fire. To achieve that, we need to define DEBUG here. // We do not do the registry override in retail SMDiagnostics because that would require shipping a test hook. We // do not generally ship test hooks today. #if DEBUG #define DEBUG_FOR_REALS #else #define DEBUG #endif namespace System.ServiceModel.Diagnostics { using System; using System.Runtime; using System.Runtime.Interop; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; using Microsoft.Win32; static class AssertUtility { #if DEBUG_FOR_REALS const string WinFXRegistryKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP"; const string WcfRegistryKey = AssertUtility.WinFXRegistryKey + @"\CDF\v4.0\Debug"; const string AssertsFailFastName = "AssertsFailFast"; #endif [Obsolete("For SMDiagnostics.dll use only. Call DiagnosticUtility.DebugAssert instead")] [SuppressMessage(FxCop.Category.ReliabilityBasic, FxCop.Rule.InvariantAssertRule, Justification = "Assert implementation")] internal static void DebugAssertCore(string message) { try { #if DEBUG_FOR_REALS string debugMessage = "WCF Assert fired! --> " + message + "\r\n"; if (Debugger.IsAttached) { Debugger.Log(0, Debugger.DefaultCategory, debugMessage); Debugger.Break(); } if (UnsafeNativeMethods.IsDebuggerPresent()) { UnsafeNativeMethods.OutputDebugString(debugMessage); UnsafeNativeMethods.DebugBreak(); } // This can be switched to just FailFast (e.g. for the stress lab). RegistryKey key = Registry.LocalMachine.OpenSubKey(AssertUtility.WcfRegistryKey); if (key != null) { object value; using (key) { value = key.GetValue(AssertUtility.AssertsFailFastName); } if (value != null && typeof(int).IsAssignableFrom(value.GetType()) && ((int) value) != 0) { try { if (ExceptionUtility.mainInstance != null) { #pragma warning disable 618 ExceptionUtility.mainInstance.TraceFailFast(message); } else { ExceptionUtility.TraceFailFast(message, new EventLogger("System.ServiceModel", null)); } #pragma warning restore 618 } finally { Environment.FailFast(message); } } } } catch (Exception exception) { message = string.Concat("Exception during assert! [", exception.GetType().Name, ": ", exception.Message, "] --> ", message); throw; #endif } finally { Debug.Assert(false, message); } } // For use within SMDiagnostics. [Conditional("DEBUG")] [Obsolete("For SMDiagnostics.dll use only. Call DiagnosticUtility.DebugAssert instead")] internal static void DebugAssert(bool condition, string message) { if (!condition) { DebugAssert(message); } } [MethodImpl(MethodImplOptions.NoInlining)] [Conditional("DEBUG")] [Obsolete("For SMDiagnostics.dll use only. Call DiagnosticUtility.DebugAssert instead")] internal static void DebugAssert(string message) { DebugAssertCore(message); } } } // 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
- InputReportEventArgs.cs
- PointF.cs
- SliderAutomationPeer.cs
- MobileUserControl.cs
- Console.cs
- BinarySecretKeyIdentifierClause.cs
- BigInt.cs
- IntPtr.cs
- GenericEnumerator.cs
- Utils.cs
- Int32Converter.cs
- CalloutQueueItem.cs
- categoryentry.cs
- xmlfixedPageInfo.cs
- XPathCompileException.cs
- BlurBitmapEffect.cs
- JsonCollectionDataContract.cs
- ToolStripKeyboardHandlingService.cs
- DateTimeUtil.cs
- DecoderExceptionFallback.cs
- CreateUserWizard.cs
- FormsAuthenticationUser.cs
- UriScheme.cs
- FixedHighlight.cs
- InfoCardClaimCollection.cs
- KeyFrames.cs
- HtmlTextArea.cs
- NGCSerializer.cs
- QueryRewriter.cs
- NameTable.cs
- SqlCacheDependency.cs
- WebPartTransformerAttribute.cs
- LayoutTable.cs
- TaiwanLunisolarCalendar.cs
- ToolStripSeparator.cs
- __Error.cs
- UITypeEditor.cs
- AudioException.cs
- ClearTypeHintValidation.cs
- DataGridViewSelectedCellCollection.cs
- MarkupWriter.cs
- MulticastNotSupportedException.cs
- FormViewModeEventArgs.cs
- NumericPagerField.cs
- sortedlist.cs
- mediaeventshelper.cs
- RelationshipConverter.cs
- HttpListenerPrefixCollection.cs
- UnauthorizedWebPart.cs
- UnmanagedMemoryStreamWrapper.cs
- SQLString.cs
- XmlNodeList.cs
- Point3D.cs
- InfiniteTimeSpanConverter.cs
- XamlStyleSerializer.cs
- ArglessEventHandlerProxy.cs
- MessageBox.cs
- TypeElement.cs
- EntityDataSourceSelectingEventArgs.cs
- UserControlFileEditor.cs
- Wildcard.cs
- WebPartCancelEventArgs.cs
- Int32CAMarshaler.cs
- FileSystemEventArgs.cs
- OleDbException.cs
- OutputScope.cs
- TransactionOptions.cs
- MouseGestureConverter.cs
- LookupNode.cs
- FrameworkTemplate.cs
- PrimaryKeyTypeConverter.cs
- TextRenderer.cs
- SafeLibraryHandle.cs
- Win32MouseDevice.cs
- OrderedDictionary.cs
- SessionStateItemCollection.cs
- ItemCollectionEditor.cs
- GeneralTransformCollection.cs
- _BufferOffsetSize.cs
- KeyboardEventArgs.cs
- MethodCallTranslator.cs
- TraceListener.cs
- SafeLibraryHandle.cs
- autovalidator.cs
- ColorTransform.cs
- SoapEnumAttribute.cs
- ScaleTransform.cs
- PropagatorResult.cs
- SafeReadContext.cs
- AssemblyResolver.cs
- SQLBytesStorage.cs
- MemberPath.cs
- PartBasedPackageProperties.cs
- ChangePasswordDesigner.cs
- TextReader.cs
- DrawingBrush.cs
- SizeFConverter.cs
- DefaultValueConverter.cs
- NativeMethods.cs
- WorkflowServiceHost.cs