Inheritance: System.ApplicationException
コード例 #1
0
 internal static void HandleTargetInvocationException(TargetInvocationException exception)
 {
     var innerException = exception.InnerException as SyncServiceException;
     if (innerException != null)
     {
         throw new SyncServiceException(innerException.StatusCode, innerException.ErrorCode, innerException.Message, exception);
     }
 }
コード例 #2
0
        public void DontStripIfNoInnerException()
        {
            TargetInvocationException wrapper = new TargetInvocationException(null);

              List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();
              Assert.AreEqual(1, exceptions.Count);
              Assert.Contains(wrapper, exceptions);
        }
コード例 #3
0
 /// <summary> Clear the value and exception and set to not-ready,
 /// allowing this FutureResult to be reused. This is not
 /// particularly recommended and must be done only
 /// when you know that no other object is depending on the
 /// properties of this FutureResult.
 ///
 /// </summary>
 public virtual void  Clear()
 {
     lock (this)
     {
         value_     = null;
         exception_ = null;
         ready_     = false;
     }
 }
コード例 #4
0
 /// <summary>
 /// Returns inner exception, while preserving the stack trace
 /// </summary>
 /// <param name="e">The target invocation exception to unwrap.</param>
 /// <returns>inner exception</returns>
 public static Exception Inner(TargetInvocationException e)
 {
     if (e == null) throw new ArgumentNullException("e");
     if (null != InternalPreserveStackTraceMethod)
     {
         InternalPreserveStackTraceMethod.Invoke(e.InnerException, new object[0]);
     }
     return e.InnerException;
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: sunriselink/OLAProject
        static void FailedTest(TargetInvocationException ex, ref int counter)
        {
            Console.ForegroundColor = GetColor(Colors.Failed);
            Console.WriteLine(@"Failed");
            Console.WriteLine(ex.InnerException.Message);
            Console.ResetColor();

            counter++;
        }
コード例 #6
0
ファイル: ExecuteException.cs プロジェクト: nhajratw/fitsharp
 private void EvaluateException(bool expression, ExecuteParameters parameters, TargetInvocationException e)
 {
     if (expression) {
         Processor.TestStatus.MarkRight(parameters.Cell);
     }
     else {
         Processor.TestStatus.MarkWrong(parameters.Cell, "exception[" + e.InnerException.GetType().Name + ": \"" + e.InnerException.Message + "\"]");
     }
 }
コード例 #7
0
        public void RemoveWrapperExceptions()
        {
            _client.RemoveWrapperExceptions(typeof(TargetInvocationException));

              TargetInvocationException wrapper = new TargetInvocationException(_exception);

              List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();
              Assert.AreEqual(1, exceptions.Count);
              Assert.Contains(wrapper, exceptions);
        }
コード例 #8
0
        public static Exception GetRealExceptionWithStackTrace(TargetInvocationException tiex)
        {
            var remoteStackTraceString = typeof(Exception).GetField("_remoteStackTraceString", BindingFlags.Instance | BindingFlags.NonPublic);

            remoteStackTraceString.SetValue(
                tiex.InnerException,
                tiex.StackTrace + Environment.NewLine
                );

            return tiex.InnerException;
        }
コード例 #9
0
        public void GetAdviceForUser_ReturnsIntroTextAsFirstLine_Always()
        {
            var fileNotFoundException = new FileNotFoundException("message about missing styles", "dummyAssemblyStyles.dll");
            var xamlParseException = new XamlParseException("", fileNotFoundException);
            var targetInvocationException = new TargetInvocationException(xamlParseException);
            var missingPreloadException = new MissingPreloadException("", targetInvocationException);

            string adviceForUser = missingPreloadException.GetAdviceForUser();

            string[] lines = adviceForUser.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            Assert.AreEqual(MissingPreloadException.IntroPartOfAdvice, lines[0]);
        }
コード例 #10
0
        public void StripAggregateExceptionAndTargetInvocationException()
        {
            _client.AddWrapperExceptions(typeof(AggregateException));

              OutOfMemoryException exception2 = new OutOfMemoryException("Ran out of Int64s");
              TargetInvocationException innerWrapper = new TargetInvocationException(exception2);
              AggregateException wrapper = new AggregateException(_exception, innerWrapper);

              List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();
              Assert.AreEqual(2, exceptions.Count);
              Assert.Contains(_exception, exceptions);
              Assert.Contains(exception2, exceptions);
        }
コード例 #11
0
ファイル: O1ExceptionClasses.cs プロジェクト: xxy1991/cozy
        public static void Cozy()
        {
            Console.WriteLine("\n-----------------------------------------------");
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
            Console.WriteLine("-----------------------------------------------");

            System.Exception e1 = new Exception();
            System.ApplicationException e2 = new ApplicationException();
            e2 = null;
            System.Reflection.TargetInvocationException e3 = new TargetInvocationException(e1);
            System.SystemException e4 = new SystemException();
            e4 = null;
            System.StackOverflowException e5 = new StackOverflowException();
            e5 = null;
        }
コード例 #12
0
ファイル: Delegate2.cs プロジェクト: zhubin-12/32feet
        static void _RunnerResult <TResult>(object state)
        {
            AsyncResult <TResult, Func <TResult> > ar = (AsyncResult <TResult, Func <TResult> >)state;
            TResult result;

            try {
                Func <TResult> dlgt = ar.BeginParameters;
                result = dlgt();
            } catch (Exception ex) {
                System.Reflection.TargetInvocationException tex
                    = CreateTargetInvocationException(ex);
                ar.SetAsCompleted(tex, false);
                return;
            }
            ar.SetAsCompleted(result, false);
        }
コード例 #13
0
ファイル: ExceptionHelper.cs プロジェクト: TheMouster/mvc
        public static Exception ResolveTargetInvocationException(TargetInvocationException ex)
        {
            if (SecurityManager.IsGranted(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)))
            {
                FieldInfo remoteStackTrace = typeof (Exception).GetField("_remoteStackTraceString",
                                                                         BindingFlags.Instance | BindingFlags.NonPublic);

                remoteStackTrace.SetValue(ex.InnerException, ex.InnerException.StackTrace + "\r\n");

                return ex.InnerException;
            }
            else
            {
                return ex;
            }
        }
コード例 #14
0
        /// <summary>
        /// Handles a subscriber method exception by passing it to all extensions and re-throwing the inner exception in case that none of the
        /// extensions handled it.
        /// </summary>
        /// <param name="targetInvocationException">The targetInvocationException.</param>
        /// <param name="eventTopic">The event topic.</param>
        protected void HandleSubscriberMethodException(TargetInvocationException targetInvocationException, IEventTopicInfo eventTopic)
        {
            Ensure.ArgumentNotNull(targetInvocationException, "targetInvocationException");

            var innerException = targetInvocationException.InnerException;
            innerException.PreserveStackTrace();

            var context = new ExceptionHandlingContext();

            this.ExtensionHost.ForEach(extension => extension.SubscriberExceptionOccurred(eventTopic, innerException, context));
                
            if (!context.Handled)
            {
                throw innerException;
            }
        }
コード例 #15
0
 /// <summary>
 /// Unwraps the TargetInvocationException that reflection methods helpfully give us.
 /// </summary>
 /// <param name="tie">Exception to unwrap</param>
 /// <returns>A copy of the inner exception, for a few cases.</returns>
 public static Exception UnwrapTargetInvokationException(TargetInvocationException tie)
 {
     if (tie.InnerException.GetType() == typeof(DataStoreCastException))
     {
         DataStoreCastException orig = (DataStoreCastException)tie.InnerException;
         return new DataStoreCastException(orig.FromType, orig.ToType, tie);
     }
     else if (tie.InnerException.GetType() == typeof(DataNode.ValueNotInitialized))
     {
         DataNode.ValueNotInitialized orig = (DataNode.ValueNotInitialized)tie.InnerException;
         throw new DataNode.ValueNotInitialized(orig.key, tie);
     }
     else if (tie.InnerException.GetType() == typeof(NotSupportedException))
     {
         NotSupportedException orig = (NotSupportedException)tie.InnerException;
         throw new NotSupportedException(orig.Message, tie);
     }
     return null;
 }
コード例 #16
0
ファイル: ScriptHost.cs プロジェクト: tzuhaochu/DVTk
        private Exception CreateExceptionForTargetParameterCountException(System.Reflection.TargetInvocationException targetInvocationException)
        {
            Exception exception = null;

            if (targetInvocationException.InnerException != null)
            {
                String message = "";

                message = targetInvocationException.InnerException.Message;

                message += "\r\n\r\nStack trace (of expanded script):\r\n" + targetInvocationException.InnerException.StackTrace;

                exception = new Exception(message);
            }
            else
            {
                exception = new Exception(targetInvocationException.Message);
            }

            return(exception);
        }
コード例 #17
0
        public static TargetInvocationException Create(
            string message_s,
            Exception inner_exception,
            string value_s1,
            string value_s2,
            SerializationInfo info_serializationInfo,
            StreamingContext context_streamingContext
            )
        {
            TargetInvocationException targetInvocationException
                = new TargetInvocationException(message_s, inner_exception);

            ((Exception)targetInvocationException).HelpLink = value_s1;
            ((Exception)targetInvocationException).Source   = value_s2;
            ((Exception)targetInvocationException).GetObjectData
                (info_serializationInfo, context_streamingContext);
            return(targetInvocationException);

            // TODO: Edit factory method of TargetInvocationException
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
コード例 #18
0
ファイル: RaygunClientTests.cs プロジェクト: robfe/raygun4net
        public void StripTargetInvocationExceptionByDefault()
        {
            TargetInvocationException wrapper = new TargetInvocationException(_exception);

              RaygunMessage message = _client.CreateMessage(wrapper);
              Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
        }
コード例 #19
0
ファイル: RaygunClientTests.cs プロジェクト: robfe/raygun4net
        public void StripMultipleWrapperExceptions()
        {
            HttpUnhandledException wrapper = new HttpUnhandledException("Something went wrong", _exception);
              TargetInvocationException wrapper2 = new TargetInvocationException(wrapper);

              RaygunMessage message = _client.CreateMessage(wrapper2);
              Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
        }
コード例 #20
0
        /// <summary>
        /// Unwraps the supplied <see cref="System.Reflection.TargetInvocationException"/> 
        /// and returns the inner exception preserving the stack trace.
        /// </summary>
        /// <param name="ex">
        /// The <see cref="System.Reflection.TargetInvocationException"/> to unwrap.
        /// </param>
        /// <returns>The unwrapped exception.</returns>
        public static Exception UnwrapTargetInvocationException(TargetInvocationException ex)
        {
#if NET_2_0
            if (SystemUtils.MonoRuntime)
            {
                return ex.InnerException;
            }
            Exception_InternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] { });
#else
            Exception_RemoteStackTraceString.SetValue(ex.InnerException, ex.InnerException.StackTrace + Environment.NewLine);
#endif
            return ex.InnerException;
        }
コード例 #21
0
    /// <summary>
    /// Starts the receive the server's network packet
    /// </summary>
    /// <returns>
    /// The receive.
    /// </returns>
    private IEnumerator StartReceive()
    {
        byte[] t_length = new byte[4];
        byte[] t_header = new byte[4];

        int tProcessedPacket = 0;

        while (Connected)
        {
            if (m_socket.Poll(true))
            {
                yield return(StartCoroutine(m_socket.Read(t_length, t_length.Length)));

                if (Connected)
                {
                    yield return(StartCoroutine(m_socket.Read(t_header, t_header.Length)));

                    if (Connected)
                    {
                        int    size  = (t_length[3] | t_length[2] << 8 | t_length[1] << 16 | t_length[0] << 24);
                        byte[] bytes = new byte[size];
                        if (size != 0)
                        {
                            yield return(StartCoroutine(m_socket.Read(bytes, size)));
                        }

                        if (Connected)
                        {
                            bool t_zip  = (t_header[0] & 0x80) == 0x80;
                            bool t_lzma = (t_header[0] & 0x40) == 0x40;
                            if (t_zip || t_lzma)
                            {
                                // clear flag
                                t_header[0] = (byte)(t_header[0] & 0x3f);
                            }

                            int opcode = (int)(t_header[3] | t_header[2] << 8 | t_header[1] << 16 | t_header[0] << 24);
                            if (t_zip || t_lzma)
                            {
                                // decompress
                                try{
                                    bytes = t_lzma ? DecompressLZMA(bytes) : DecompressGZip(bytes);
                                }catch (System.Exception e) {
                                    Debug.LogError(e.Message + "\n" + e.StackTrace);
                                    GZIPHeaderBrokenProcess();
                                }
                            }

                            try{
                                DistributePacket(opcode, bytes);
                            } catch (System.Exception e) {
                                if (e is System.Reflection.TargetInvocationException)
                                {
                                    System.Reflection.TargetInvocationException ex = (System.Reflection.TargetInvocationException)e;
                                    e = ex.InnerException;
                                }
                                Debug.LogError(e.Message + "\n" + e.StackTrace);
                            }
                        }
                    }
                }

                if (++tProcessedPacket > 5)
                {
                    tProcessedPacket = 0;
                    yield return(null);
                }
            }
            else
            {
                tProcessedPacket = 0;
                yield return(null);
            }
        }
    }
コード例 #22
0
		private static void HandleException(ref RunningResults results, TargetInvocationException ex)
		{
			HandleInnerException(ref results, (dynamic)ex.InnerException);
		}
コード例 #23
0
        public void StripMultipleWrapperExceptions()
        {
            _client.AddWrapperExceptions(typeof(WrapperException));

              WrapperException wrapper = new WrapperException(_exception);
              TargetInvocationException wrapper2 = new TargetInvocationException(wrapper);

              List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper2).ToList();
              Assert.AreEqual(1, exceptions.Count);
              Assert.Contains(_exception, exceptions);
        }
コード例 #24
0
        private void ParseXml(XmlTextReader reader) {
            bool success = false;
            try {
                try {
                    while (reader.Read()) {
                        if (reader.NodeType == XmlNodeType.Element) {
                            string s = reader.LocalName;
                            
                            if (reader.LocalName.Equals(ResXResourceWriter.AssemblyStr)) {
                                ParseAssemblyNode(reader, false);
                            }
                            else if (reader.LocalName.Equals(ResXResourceWriter.DataStr)) {
                                ParseDataNode(reader, false);
                            }
                            else if (reader.LocalName.Equals(ResXResourceWriter.ResHeaderStr)) {
                                ParseResHeaderNode(reader);
                            }
                            else if (reader.LocalName.Equals(ResXResourceWriter.MetadataStr)) {
                                ParseDataNode(reader, true);
                            }
                        }
                    }

                    success = true;
                }
                catch (SerializationException se) {
                    Point pt = GetPosition(reader);
                    string newMessage = SR.GetString(SR.SerializationException, reader[ResXResourceWriter.TypeStr], pt.Y, pt.X, se.Message);
                    XmlException xml = new XmlException(newMessage, se, pt.Y, pt.X);
                    SerializationException newSe = new SerializationException(newMessage, xml);

                    throw newSe;
                }
                catch (TargetInvocationException tie) {
                    Point pt = GetPosition(reader);
                    string newMessage = SR.GetString(SR.InvocationException, reader[ResXResourceWriter.TypeStr], pt.Y, pt.X, tie.InnerException.Message);
                    XmlException xml = new XmlException(newMessage, tie.InnerException, pt.Y, pt.X);
                    TargetInvocationException newTie = new TargetInvocationException(newMessage, xml);

                    throw newTie;
                }
                catch (XmlException e) {
                    throw new ArgumentException(SR.GetString(SR.InvalidResXFile, e.Message), e);
                }
                catch (Exception e) {
                    if (ClientUtils.IsSecurityOrCriticalException(e)) {
                        throw;
                    } else {
                        Point pt = GetPosition(reader);
                        XmlException xmlEx = new XmlException(e.Message, e, pt.Y, pt.X);
                        throw new ArgumentException(SR.GetString(SR.InvalidResXFile, xmlEx.Message), xmlEx);
                    }
                }
            }
            finally {
                if (!success) {
                    resData = null;
                    resMetadata = null;
                }
            }

            bool validFile = false;

            if (object.Equals(resHeaderMimeType, ResXResourceWriter.ResMimeType)) {

                Type readerType = typeof(ResXResourceReader);
                Type writerType = typeof(ResXResourceWriter);

                string readerTypeName = resHeaderReaderType;
                string writerTypeName = resHeaderWriterType;
                if (readerTypeName != null &&readerTypeName.IndexOf(',') != -1) {
                    readerTypeName = readerTypeName.Split(new char[] {','})[0].Trim();
                }
                if (writerTypeName != null && writerTypeName.IndexOf(',') != -1) {
                    writerTypeName = writerTypeName.Split(new char[] {','})[0].Trim();
                }

// Don't check validity, since our reader/writer classes are in System.Web.Compilation,
// while the file format has them in System.Resources.  
#if SYSTEM_WEB
                validFile = true;
#else
                if (readerTypeName != null && 
                    writerTypeName != null && 
                    readerTypeName.Equals(readerType.FullName) && 
                    writerTypeName.Equals(writerType.FullName)) {
                    validFile = true;
                }
#endif
            }

            if (!validFile) {
                resData = null;
                resMetadata = null;
                throw new ArgumentException(SR.GetString(SR.InvalidResXFileReaderWriterTypes));
            }
        }
コード例 #25
0
        public void RemoveWrapperExceptions()
        {
            _client.RemoveWrapperExceptions(typeof(TargetInvocationException));

              TargetInvocationException wrapper = new TargetInvocationException(_exception);

              RaygunMessage message = _client.ExposeBuildMessage(wrapper);
              Assert.AreEqual("System.Reflection.TargetInvocationException", message.Details.Error.ClassName);
        }
コード例 #26
0
 /// <summary>
 /// Called when an exception was swallowed.
 /// </summary>
 /// <param name="targetInvocationException">The target invocation exception.</param>
 /// <param name="message">The message.</param>
 /// <param name="controlledModule">The controlled module.</param>
 public virtual void SwallowedException(TargetInvocationException targetInvocationException, object message, object controlledModule)
 {
 }
コード例 #27
0
 internal static string FormatTargetInvocationException(TargetInvocationException exception)
 {
     var i = exception.InnerException;
     return String.Format("(threw {0})", i.GetType().Name);
 }
コード例 #28
0
 public static string DisplayMessage(System.Reflection.TargetInvocationException exception)
 {
     throw null;
 }
コード例 #29
0
ファイル: ReflectHelper.cs プロジェクト: zibler/zibler
 /// <summary>
 /// Unwraps the supplied <see cref="System.Reflection.TargetInvocationException"/> 
 /// and returns the inner exception preserving the stack trace.
 /// </summary>
 /// <param name="ex">
 /// The <see cref="System.Reflection.TargetInvocationException"/> to unwrap.
 /// </param>
 /// <returns>The unwrapped exception.</returns>
 public static Exception UnwrapTargetInvocationException(TargetInvocationException ex)
 {
     Exception_InternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] {});
     return ex.InnerException;
 }
コード例 #30
0
ファイル: Samples.cs プロジェクト: stemarie/CLAP
 public void Error(TargetInvocationException ex)
 {
 }
コード例 #31
0
 private Exception InnerExceptionWhilePreservingStackTrace(TargetInvocationException e)
 {
     internalPreserveStackTraceMethod.Invoke(e.InnerException, new object[0]);
     return e.InnerException;
 }
コード例 #32
0
 /// <summary>
 /// Called when an exception was swallowed.
 /// </summary>
 /// <param name="targetInvocationException">The target invocation exception.</param>
 /// <param name="message">The message.</param>
 /// <param name="controlledModule">The controlled module.</param>
 public void SwallowedException(TargetInvocationException targetInvocationException, object message, object controlledModule)
 {
     this.log.DebugFormat("Swallowing exception {0} that occurred consuming message {1} of module {2}.", targetInvocationException, message, controlledModule);
 }
コード例 #33
0
        public void StripTargetInvocationExceptionByDefault()
        {
            TargetInvocationException wrapper = new TargetInvocationException(_exception);

              List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();
              Assert.AreEqual(1, exceptions.Count);
              Assert.Contains(_exception, exceptions);
        }
コード例 #34
0
 static string FormatTargetInvocationException(TargetInvocationException exception)
 {
     var i = exception.InnerException;
     return string.Format("{0}: {1}", i.GetType().Name, i.Message);
 }
コード例 #35
0
        private bool WasExceptionExpected(TargetInvocationException actualException)
        {
            var expectedExceptionAttribute = _testMethodInfo.GetCustomAttribute<ExpectedExceptionAttribute>();

            if (actualException.InnerException == null || expectedExceptionAttribute == null)
                return false;

            var actualExceptionType = actualException.InnerException.GetType();
            var expectedExceptionType = expectedExceptionAttribute.ExceptionType;

            var wasExceptionExpected =
                expectedExceptionType == actualExceptionType ||
                expectedExceptionAttribute.AllowDerivedTypes &&
                actualExceptionType.IsSubclassOf(expectedExceptionType);

            return wasExceptionExpected;
        }
コード例 #36
0
ファイル: TypeMethodImpl.cs プロジェクト: db48x/KeeFox
 private static Exception TranslateException(TargetInvocationException e)
 {
     return new TargetMethodException(e.InnerException);
 }