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
- SqlConnectionHelper.cs
- HtmlControl.cs
- BordersPage.cs
- LogManagementAsyncResult.cs
- Model3D.cs
- StylusPointPropertyId.cs
- BinaryMessageFormatter.cs
- RSAPKCS1SignatureDeformatter.cs
- TypeConverterAttribute.cs
- AnimationTimeline.cs
- CompiledQueryCacheKey.cs
- XPathPatternParser.cs
- AtomMaterializerLog.cs
- Root.cs
- ByteStreamGeometryContext.cs
- DeflateEmulationStream.cs
- DateTimeEditor.cs
- srgsitem.cs
- CellParagraph.cs
- RawMouseInputReport.cs
- HorizontalAlignConverter.cs
- ChangeProcessor.cs
- KeyGestureConverter.cs
- DateRangeEvent.cs
- TextServicesManager.cs
- CacheDependency.cs
- DesigntimeLicenseContextSerializer.cs
- _WinHttpWebProxyDataBuilder.cs
- ToolStripOverflow.cs
- Comparer.cs
- UrlPropertyAttribute.cs
- CalendarDataBindingHandler.cs
- InputGestureCollection.cs
- FontUnitConverter.cs
- MenuItemBindingCollection.cs
- CodeCatchClauseCollection.cs
- ModelVisual3D.cs
- ColumnCollection.cs
- HtmlUtf8RawTextWriter.cs
- Literal.cs
- BindUriHelper.cs
- FormView.cs
- BrowserDefinition.cs
- JavascriptCallbackResponseProperty.cs
- CustomErrorsSection.cs
- CodeRemoveEventStatement.cs
- XPathConvert.cs
- WebPartCollection.cs
- Type.cs
- CatalogZone.cs
- input.cs
- SequenceDesigner.cs
- TargetInvocationException.cs
- Context.cs
- DescriptionCreator.cs
- GB18030Encoding.cs
- XmlCompatibilityReader.cs
- BaseDataBoundControl.cs
- HGlobalSafeHandle.cs
- WebPartRestoreVerb.cs
- IntegerValidator.cs
- ConfigurationProperty.cs
- PerformanceCounterPermissionEntry.cs
- XmlHierarchicalDataSourceView.cs
- HyperLinkStyle.cs
- SchemaImporterExtensionElement.cs
- ProcessHost.cs
- GlyphsSerializer.cs
- SqlBooleanMismatchVisitor.cs
- SendActivityDesignerTheme.cs
- SamlEvidence.cs
- printdlgexmarshaler.cs
- PrtCap_Public_Simple.cs
- NumberFormatter.cs
- Window.cs
- ButtonPopupAdapter.cs
- SqlServices.cs
- PerformanceCounterPermissionEntryCollection.cs
- AuthenticateEventArgs.cs
- SystemIcons.cs
- SyndicationFeedFormatter.cs
- BooleanSwitch.cs
- DynamicDataExtensions.cs
- Attributes.cs
- SamlNameIdentifierClaimResource.cs
- diagnosticsswitches.cs
- TileBrush.cs
- RoleService.cs
- SqlDataSourceConfigureFilterForm.cs
- MD5.cs
- CollectionMarkupSerializer.cs
- VideoDrawing.cs
- BinaryMessageFormatter.cs
- Window.cs
- EdmProviderManifest.cs
- EntityContainerRelationshipSet.cs
- BooleanAnimationUsingKeyFrames.cs
- DrawingState.cs
- wpf-etw.cs
- PropertyOverridesTypeEditor.cs