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
- RuntimeCompatibilityAttribute.cs
- DefinitionUpdate.cs
- ReferentialConstraintRoleElement.cs
- LogicalExpr.cs
- Exceptions.cs
- FixUpCollection.cs
- GcHandle.cs
- TextTreeInsertUndoUnit.cs
- MetadataItemSerializer.cs
- DictionaryBase.cs
- CheckBoxRenderer.cs
- XmlWhitespace.cs
- OuterGlowBitmapEffect.cs
- LowerCaseStringConverter.cs
- EmptyEnumerator.cs
- InitializationEventAttribute.cs
- UdpRetransmissionSettings.cs
- SslStream.cs
- ChannelServices.cs
- CursorInteropHelper.cs
- webbrowsersite.cs
- PrtTicket_Editor.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- StrokeCollectionConverter.cs
- XmlSchemaException.cs
- precedingsibling.cs
- StylusDownEventArgs.cs
- XmlAttributeAttribute.cs
- BaseCodeDomTreeGenerator.cs
- XmlSchemaObjectTable.cs
- TokenizerHelper.cs
- TreeViewDesigner.cs
- CodeCastExpression.cs
- TagPrefixAttribute.cs
- HGlobalSafeHandle.cs
- ExtractedStateEntry.cs
- PathFigureCollection.cs
- StylusPointProperty.cs
- AffineTransform3D.cs
- SmiSettersStream.cs
- ApplicationTrust.cs
- HwndHost.cs
- DisplayInformation.cs
- DataGridViewCellParsingEventArgs.cs
- SoapAttributeAttribute.cs
- ImageListImage.cs
- SourceLineInfo.cs
- DocumentViewerBaseAutomationPeer.cs
- Transform.cs
- ControlEvent.cs
- CreateUserWizard.cs
- DetailsViewPageEventArgs.cs
- ObjectListTitleAttribute.cs
- IsolatedStorageException.cs
- LookupBindingPropertiesAttribute.cs
- TextContainerChangeEventArgs.cs
- DocumentScope.cs
- MethodToken.cs
- SqlUtil.cs
- DataGridRowHeader.cs
- StsCommunicationException.cs
- Message.cs
- Rules.cs
- CompiledQueryCacheEntry.cs
- AVElementHelper.cs
- ScriptHandlerFactory.cs
- Tablet.cs
- JournalNavigationScope.cs
- Matrix3DStack.cs
- CodeStatement.cs
- BindingContext.cs
- UnsafeNativeMethods.cs
- MinMaxParagraphWidth.cs
- CompilerTypeWithParams.cs
- MenuCommandService.cs
- SchemaSetCompiler.cs
- ApplicationGesture.cs
- Rect3D.cs
- Block.cs
- VisualStyleTypesAndProperties.cs
- EntityUtil.cs
- BamlLocalizationDictionary.cs
- TypeContext.cs
- TemplateKey.cs
- COM2Enum.cs
- FormViewModeEventArgs.cs
- RtfToXamlReader.cs
- TypeContext.cs
- ObjectListFieldsPage.cs
- Form.cs
- ColumnResult.cs
- DisplayInformation.cs
- PrintPageEvent.cs
- SoapTypeAttribute.cs
- webbrowsersite.cs
- ToolStripOverflow.cs
- FormatterServicesNoSerializableCheck.cs
- RewritingSimplifier.cs
- TypeLoadException.cs
- DataGridPageChangedEventArgs.cs