Exemplo n.º 1
0
        public static Exception PrepareForRethrow(this Exception exception)
        {
            Fx.Assert(exception != null, "The specified Exception is null.");

            if (!ShouldPrepareForRethrow(exception))
            {
                return(exception);
            }

#if !DNXCORE
            if (PartialTrustHelpers.UnsafeIsInFullTrust())
#endif
            {
                // Racing here is harmless
                if (ExceptionExtensions.prepForRemotingMethodInfo == null)
                {
                    ExceptionExtensions.prepForRemotingMethodInfo =
                        typeof(Exception).GetMethod("PrepForRemoting", BindingFlags.Instance | BindingFlags.NonPublic);
                }

                if (ExceptionExtensions.prepForRemotingMethodInfo != null)
                {
                    // PrepForRemoting is not thread-safe. When the same exception instance is thrown by multiple threads
                    // the remote stack trace string may not format correctly. However, We don't lock this to protect us from it given
                    // it is discouraged to throw the same exception instance from multiple threads and the side impact is ignorable.
                    prepForRemotingMethodInfo.Invoke(exception, new object[] { });
                }
            }

            return(exception);
        }
Exemplo n.º 2
0
        protected void Schedule()
        {
            if (isScheduled)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(CommonResources.ActionItemIsAlreadyScheduled));
            }

            this.isScheduled = true;
#if !NETSTANDARD
            if (PartialTrustHelpers.ShouldFlowSecurityContext)
            {
                this.context = PartialTrustHelpers.CaptureSecurityContextNoIdentityFlow();
            }
            if (this.context != null)
            {
                ScheduleCallback(CallbackHelper.InvokeWithContextCallback);
            }
            else
#endif // !NETSTANDARD
            {
                ScheduleCallback(CallbackHelper.InvokeWithoutContextCallback);
            }
        }