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
- HtmlContainerControl.cs
- SoapSchemaMember.cs
- Pen.cs
- Border.cs
- ChannelSettingsElement.cs
- GridViewSortEventArgs.cs
- CodeTypeDeclaration.cs
- CryptoConfig.cs
- InvalidWMPVersionException.cs
- ScopelessEnumAttribute.cs
- Point3DConverter.cs
- WebPartExportVerb.cs
- Compilation.cs
- MarkupObject.cs
- LoginUtil.cs
- BindingContext.cs
- MessageContractExporter.cs
- XamlToRtfWriter.cs
- SelectionRangeConverter.cs
- SecurityTokenProvider.cs
- MenuItemStyleCollection.cs
- WebPartManager.cs
- XsltOutput.cs
- SecurityContext.cs
- AutomationPropertyInfo.cs
- GridItemPattern.cs
- TextElementEnumerator.cs
- Fonts.cs
- OleDbEnumerator.cs
- ConsumerConnectionPointCollection.cs
- EntityDataSourceStatementEditorForm.cs
- FontStretchConverter.cs
- ConfigXmlElement.cs
- CharEnumerator.cs
- ContentPlaceHolder.cs
- XmlRawWriter.cs
- ServicesUtilities.cs
- printdlgexmarshaler.cs
- RangeEnumerable.cs
- ReceiveContent.cs
- PriorityBindingExpression.cs
- SqlConnectionFactory.cs
- WebResourceUtil.cs
- EncoderReplacementFallback.cs
- SHA256Managed.cs
- WebColorConverter.cs
- Rectangle.cs
- EventLogTraceListener.cs
- SynchronizedDispatch.cs
- FormatPage.cs
- SafePEFileHandle.cs
- CharacterHit.cs
- BlurBitmapEffect.cs
- SizeChangedEventArgs.cs
- ThrowHelper.cs
- WebPartConnectionsDisconnectVerb.cs
- PixelShader.cs
- Point.cs
- ProtectedConfiguration.cs
- WebSysDescriptionAttribute.cs
- XmlSchemaExternal.cs
- WebEventCodes.cs
- CopyAttributesAction.cs
- Geometry.cs
- PageTheme.cs
- addressfiltermode.cs
- PagedDataSource.cs
- CheckedListBox.cs
- StylusPointProperties.cs
- QfeChecker.cs
- LayoutTable.cs
- CompModSwitches.cs
- AttributeUsageAttribute.cs
- RTLAwareMessageBox.cs
- RuleSettings.cs
- MULTI_QI.cs
- SqlTopReducer.cs
- TypeDescriptionProviderAttribute.cs
- ResourceCollectionInfo.cs
- Solver.cs
- TaiwanCalendar.cs
- SiteMapNodeCollection.cs
- PrintDialog.cs
- ActiveXContainer.cs
- QilInvoke.cs
- ImageClickEventArgs.cs
- InvalidOperationException.cs
- BinHexDecoder.cs
- HostingEnvironmentException.cs
- InputLanguageProfileNotifySink.cs
- HttpHandlerAction.cs
- StubHelpers.cs
- TimeEnumHelper.cs
- EntityReference.cs
- XslCompiledTransform.cs
- ArgumentOutOfRangeException.cs
- TreeViewHitTestInfo.cs
- CompilationLock.cs
- PrimitiveCodeDomSerializer.cs
- SingleObjectCollection.cs