コード例 #1
0
        public static Exception PrepareForRethrow(this Exception exception)
        {
            Fx.Assert(exception != null, "The specified Exception is null.");

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

            if (PartialTrustHelpers.UnsafeIsInFullTrust())
            {
                // Racing here is harmless
                if (ExceptionExtensions.prepForRemotingMethodInfo == null)
                {
                    ExceptionExtensions.prepForRemotingMethodInfo =
                        typeof(Exception).GetMethod("PrepForRemoting", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { }, new ParameterModifier[] { });
                }

                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);
        }
コード例 #2
0
ファイル: ActionItem.cs プロジェクト: jgondres/Azure-ioT-C-
        protected void Schedule()
        {
            if (isScheduled)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(CommonResources.ActionItemIsAlreadyScheduled));
            }

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