Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / System.Runtime.DurableInstancing / System / Runtime / AssertHelper.cs / 1305376 / AssertHelper.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 // build of this assembly should still have asserts fire. To achieve that, we need to define DEBUG here. // We do not do the registry override in retail 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.Runtime { using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.Interop; using System.Security; using System.Runtime.Versioning; static class AssertHelper { [SuppressMessage(FxCop.Category.ReliabilityBasic, FxCop.Rule.InvariantAssertRule, Justification = "Assert implementation")] [ResourceConsumption(ResourceScope.Process)] internal static void FireAssert(string message) { try { #if DEBUG_FOR_REALS InternalFireAssert(ref message); #endif } finally { Debug.Assert(false, message); } } #if DEBUG_FOR_REALS [SuppressMessage(FxCop.Category.Globalization, FxCop.Rule.DoNotPassLiteralsAsLocalizedParameters, Justification = "Debug Only")] [Fx.Tag.SecurityNote(Critical = "Calls into various critical methods", Safe = "Exists only on debug versions")] [SecuritySafeCritical] static void InternalFireAssert(ref string message) { try { string debugMessage = "Assert fired! --> " + message + "\r\n"; if (Debugger.IsAttached) { Debugger.Log(0, Debugger.DefaultCategory, debugMessage); Debugger.Break(); } if (UnsafeNativeMethods.IsDebuggerPresent()) { UnsafeNativeMethods.OutputDebugString(debugMessage); UnsafeNativeMethods.DebugBreak(); } if (Fx.AssertsFailFast) { try { Fx.Exception.TraceFailFast(message); } finally { Environment.FailFast(message); } } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } string newMessage = "Exception during FireAssert!"; try { newMessage = string.Concat(newMessage, " [", exception.GetType().Name, ": ", exception.Message, "] --> ", message); } finally { message = newMessage; } throw; } } #endif } } // 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 // build of this assembly should still have asserts fire. To achieve that, we need to define DEBUG here. // We do not do the registry override in retail 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.Runtime { using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.Interop; using System.Security; using System.Runtime.Versioning; static class AssertHelper { [SuppressMessage(FxCop.Category.ReliabilityBasic, FxCop.Rule.InvariantAssertRule, Justification = "Assert implementation")] [ResourceConsumption(ResourceScope.Process)] internal static void FireAssert(string message) { try { #if DEBUG_FOR_REALS InternalFireAssert(ref message); #endif } finally { Debug.Assert(false, message); } } #if DEBUG_FOR_REALS [SuppressMessage(FxCop.Category.Globalization, FxCop.Rule.DoNotPassLiteralsAsLocalizedParameters, Justification = "Debug Only")] [Fx.Tag.SecurityNote(Critical = "Calls into various critical methods", Safe = "Exists only on debug versions")] [SecuritySafeCritical] static void InternalFireAssert(ref string message) { try { string debugMessage = "Assert fired! --> " + message + "\r\n"; if (Debugger.IsAttached) { Debugger.Log(0, Debugger.DefaultCategory, debugMessage); Debugger.Break(); } if (UnsafeNativeMethods.IsDebuggerPresent()) { UnsafeNativeMethods.OutputDebugString(debugMessage); UnsafeNativeMethods.DebugBreak(); } if (Fx.AssertsFailFast) { try { Fx.Exception.TraceFailFast(message); } finally { Environment.FailFast(message); } } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } string newMessage = "Exception during FireAssert!"; try { newMessage = string.Concat(newMessage, " [", exception.GetType().Name, ": ", exception.Message, "] --> ", message); } finally { message = newMessage; } throw; } } #endif } } // 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
- UITypeEditors.cs
- IconBitmapDecoder.cs
- DataServiceKeyAttribute.cs
- IDQuery.cs
- PrinterSettings.cs
- WindowsSpinner.cs
- TripleDES.cs
- CultureTable.cs
- AsyncOperationManager.cs
- ObjectViewFactory.cs
- FileDialogCustomPlaces.cs
- ControlAdapter.cs
- DefaultHttpHandler.cs
- OutOfMemoryException.cs
- InvokeMethodActivityDesigner.cs
- WeakRefEnumerator.cs
- InvalidEnumArgumentException.cs
- ScrollChrome.cs
- AutomationPatternInfo.cs
- SettingsProviderCollection.cs
- LinkClickEvent.cs
- XmlHierarchicalEnumerable.cs
- HuffCodec.cs
- DbConnectionPool.cs
- HostedHttpContext.cs
- WindowsListViewItemCheckBox.cs
- ViewBase.cs
- TimeoutException.cs
- ProcessExitedException.cs
- TargetParameterCountException.cs
- Shape.cs
- PrintDialogDesigner.cs
- CaseInsensitiveHashCodeProvider.cs
- Unit.cs
- Vector3DAnimation.cs
- HttpCookie.cs
- CombinedGeometry.cs
- CodeConstructor.cs
- XmlSchemaAll.cs
- Symbol.cs
- SetStoryboardSpeedRatio.cs
- StylusEditingBehavior.cs
- RoleService.cs
- StylusPointProperty.cs
- EventProxy.cs
- MemoryMappedFile.cs
- DeclarativeCatalogPart.cs
- Property.cs
- DesignerTextViewAdapter.cs
- XsdDateTime.cs
- Byte.cs
- TextElement.cs
- SafeNativeMemoryHandle.cs
- FileLevelControlBuilderAttribute.cs
- MsdtcWrapper.cs
- PerformanceCounterLib.cs
- QilList.cs
- StateMachineSubscription.cs
- ProfileSettingsCollection.cs
- SqlFlattener.cs
- BamlLocalizableResourceKey.cs
- TextElementEnumerator.cs
- wgx_commands.cs
- ErrorFormatterPage.cs
- SQLInt64Storage.cs
- CodeAttributeArgument.cs
- LongTypeConverter.cs
- ErrorFormatterPage.cs
- SafeFileMappingHandle.cs
- PropertyDescriptors.cs
- SapiRecoInterop.cs
- OwnerDrawPropertyBag.cs
- DependencySource.cs
- RemoteHelper.cs
- RangeContentEnumerator.cs
- Variant.cs
- DictionarySectionHandler.cs
- ConnectionPoint.cs
- RightsManagementProvider.cs
- _Semaphore.cs
- AsyncStreamReader.cs
- XPathArrayIterator.cs
- DataSourceProvider.cs
- StorageScalarPropertyMapping.cs
- FacetValueContainer.cs
- UnsafeNativeMethods.cs
- NamespaceTable.cs
- QueueAccessMode.cs
- PropertyChangedEventArgs.cs
- AssemblyLoader.cs
- FrameworkElementFactoryMarkupObject.cs
- FixedSOMTableRow.cs
- SoapSchemaImporter.cs
- ProbeMatches11.cs
- XmlMapping.cs
- SplitterEvent.cs
- MimeTypeMapper.cs
- DependencyPropertyHelper.cs
- TimerElapsedEvenArgs.cs
- ControlIdConverter.cs