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
- TextWriter.cs
- OverflowException.cs
- Brush.cs
- MultiPropertyDescriptorGridEntry.cs
- SchemaMapping.cs
- EdmToObjectNamespaceMap.cs
- TreeIterator.cs
- Border.cs
- FileStream.cs
- ClickablePoint.cs
- ProjectionQueryOptionExpression.cs
- DataRecord.cs
- CharEnumerator.cs
- TextParagraphProperties.cs
- SystemDropShadowChrome.cs
- FormsIdentity.cs
- NativeMethodsCLR.cs
- ExpressionVisitor.cs
- IconBitmapDecoder.cs
- WpfWebRequestHelper.cs
- RefreshEventArgs.cs
- BaseDataList.cs
- ExpressionBuilderContext.cs
- OleDbPropertySetGuid.cs
- HtmlGenericControl.cs
- CultureTable.cs
- ImageMapEventArgs.cs
- EntityDesignerDataSourceView.cs
- ObjectAssociationEndMapping.cs
- ReceiveActivity.cs
- WebPartUtil.cs
- HtmlInputImage.cs
- SerializableTypeCodeDomSerializer.cs
- SchemaAttDef.cs
- SerializationInfo.cs
- TextEditorSpelling.cs
- CompiledQueryCacheEntry.cs
- BulletedListEventArgs.cs
- securestring.cs
- Expression.DebuggerProxy.cs
- EventLogPermission.cs
- DesignerVerbCollection.cs
- CommandCollectionEditor.cs
- ChildDocumentBlock.cs
- DataGridDetailsPresenterAutomationPeer.cs
- IDReferencePropertyAttribute.cs
- EntityContainer.cs
- ResourceManager.cs
- TakeOrSkipQueryOperator.cs
- WebControlParameterProxy.cs
- HttpRequest.cs
- ChannelManager.cs
- KeyPullup.cs
- StrokeIntersection.cs
- DrawListViewItemEventArgs.cs
- EventProvider.cs
- iisPickupDirectory.cs
- UITypeEditor.cs
- PathFigureCollectionConverter.cs
- URLString.cs
- ScriptControlManager.cs
- CodeCommentStatement.cs
- QueryContinueDragEventArgs.cs
- DirtyTextRange.cs
- EntitySqlQueryCacheEntry.cs
- TreeViewHitTestInfo.cs
- XmlEnumAttribute.cs
- OdbcConnectionHandle.cs
- ParameterBuilder.cs
- ContentFilePart.cs
- MissingMemberException.cs
- NumberSubstitution.cs
- LoginName.cs
- OdbcStatementHandle.cs
- StateMachineWorkflowInstance.cs
- VoiceChangeEventArgs.cs
- ActivityTrace.cs
- ExtenderProvidedPropertyAttribute.cs
- DesignerLoader.cs
- EdgeModeValidation.cs
- TypeSystemProvider.cs
- ConstructorBuilder.cs
- ListViewItem.cs
- DateTimeFormatInfo.cs
- MissingMemberException.cs
- Object.cs
- WebPartCancelEventArgs.cs
- DBAsyncResult.cs
- GeneralTransform3DCollection.cs
- DataServiceResponse.cs
- CharConverter.cs
- SubqueryRules.cs
- BufferBuilder.cs
- ListViewAutomationPeer.cs
- SelectorItemAutomationPeer.cs
- FileDialogCustomPlace.cs
- VBIdentifierNameEditor.cs
- Paragraph.cs
- MetadataCacheItem.cs
- MulticastNotSupportedException.cs