protected void Complete(bool didCompleteSynchronously, Exception e) { if (!TryComplete(didCompleteSynchronously, e)) { throw Fx.Exception.AsError( new InvalidOperationException(CommonResources.GetString(Resources.AsyncResultCompletedTwice, GetType()))); } }
public void SetAt(long newDueTimeInTicks) { if (newDueTimeInTicks >= TimeSpan.MaxValue.Ticks || newDueTimeInTicks < 0) { throw Fx.Exception.ArgumentOutOfRange( "newDueTime", newDueTimeInTicks, CommonResources.GetString(CommonResources.ArgumentOutOfRange, 0, TimeSpan.MaxValue.Ticks - 1)); } TimerManager.Value.Set(this, newDueTimeInTicks); }
////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) { // 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)); } }
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 Exception AssertAndFailFastService(string description) { Assert(description); string failFastMessage = CommonResources.GetString(Resources.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 { Thread.Sleep(TimeSpan.FromSeconds(15)); } finally { // ########################## 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 var failFastWorkaroundThread = new Thread( delegate() { #pragma warning disable CA2219 // Do not raise exceptions in finally clauses throw new FatalException(failFastMessage); #pragma warning restore CA2219 // Do not raise exceptions in finally clauses }); failFastWorkaroundThread.Start(); failFastWorkaroundThread.Join(); } } catch { throw; } return(null); // we'll never get here since we've just fail-fasted }
public ArgumentException ArgumentNullOrWhiteSpace(string paramName) { return(this.Argument(paramName, CommonResources.GetString(CommonResources.ArgumentNullOrWhiteSpace, paramName))); }
public ArgumentException ArgumentNullOrEmpty(string paramName) { return(Argument(paramName, CommonResources.GetString(CommonResources.ArgumentNullOrEmpty, paramName))); }
public AssertionFailedException(string description) : base(CommonResources.GetString(CommonResources.ShipAssertExceptionMessage, description)) { }
protected static void ThrowInvalidAsyncResult(IAsyncResult result) { throw Fx.Exception.AsError(new InvalidOperationException(CommonResources.GetString(CommonResources.InvalidAsyncResultImplementation, result.GetType()))); }