public static Exception AssertAndFailFastService(string description) { Fx.Assert(description); string failFastMessage = CommonResources.GetString(CommonResources.FailFastMessage, description); // The catch is here to force the finally to run, as finallys don't run until the stack walk gets to a catch. // The catch makes sure that the finally will run before the stack-walk leaves the frame, but the code inside is impossible to reach. try { try { ////MessagingClientEtwProvider.Provider.EventWriteFailFastOccurred(description); Fx.Exception.TraceFailFast(failFastMessage); // Mark that a FailFast is in progress, so that we can take ourselves out of the NLB if for // any reason we can't kill ourselves quickly. Wait 15 seconds so this state gets picked up for sure. Fx.FailFastInProgress = true; #if !WINDOWS_UWP Thread.Sleep(TimeSpan.FromSeconds(15)); #endif } finally { #if !WINDOWS_UWP // ########################## NOTE ########################### // Environment.FailFast does not collect crash dumps when used in Azure services. // Environment.FailFast(failFastMessage); // ################## WORKAROUND ############################# // Workaround for the issue above. Throwing an unhandled exception on a separate thread to trigger process crash and crash dump collection // Throwing FatalException since our service does not morph/eat up fatal exceptions // We should find the tracking bug in Azure for this issue, and remove the workaround when fixed by Azure Thread failFastWorkaroundThread = new Thread(delegate() { throw new FatalException(failFastMessage); }); failFastWorkaroundThread.Start(); failFastWorkaroundThread.Join(); #endif } } catch { throw; } return(null); // we'll never get here since we've just fail-fasted }
////public static DiagnosticTrace Trace ////{ //// get //// { //// if (diagnosticTrace == null) //// { //// diagnosticTrace = InitializeTracing(); //// } //// return diagnosticTrace; //// } ////} public static byte[] AllocateByteArray(int size) { try { // Safe to catch OOM from this as long as the ONLY thing it does is a simple allocation of a primitive type (no method calls). return(new byte[size]); } catch (OutOfMemoryException exception) { #if WINDOWS_UWP // InsufficientMemoryException does not exit in UWP, fall back to OutOfMemoryException throw Fx.Exception.AsError(new OutOfMemoryException(CommonResources.GetString(CommonResources.BufferAllocationFailed, size), exception)); #else // Convert OOM into an exception that can be safely handled by higher layers. throw Fx.Exception.AsError(new InsufficientMemoryException(CommonResources.GetString(CommonResources.BufferAllocationFailed, size), exception)); #endif } }
protected static void ThrowInvalidAsyncResult(IAsyncResult result) { throw Fx.Exception.AsError(new InvalidOperationException(CommonResources.GetString(CommonResources.InvalidAsyncResultImplementation, result.GetType()))); }
public ArgumentException ArgumentNullOrWhiteSpace(string paramName) { return(this.Argument(paramName, CommonResources.GetString(CommonResources.ArgumentNullOrWhiteSpace, paramName))); }