Inheritance: System.ApplicationException
 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);
     }
 }
        public void DontStripIfNoInnerException()
        {
            TargetInvocationException wrapper = new TargetInvocationException(null);

              List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();
              Assert.AreEqual(1, exceptions.Count);
              Assert.Contains(wrapper, exceptions);
        }
Example #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;
     }
 }
Example #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;
 }
Example #5
0
        static void FailedTest(TargetInvocationException ex, ref int counter)
        {
            Console.ForegroundColor = GetColor(Colors.Failed);
            Console.WriteLine(@"Failed");
            Console.WriteLine(ex.InnerException.Message);
            Console.ResetColor();

            counter++;
        }
Example #6
0
 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 + "\"]");
     }
 }
        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);
        }
Example #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;
        }
        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]);
        }
Example #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);
        }
Example #11
0
        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;
        }
Example #12
0
        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);
        }
Example #13
0
        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;
            }
        }
        /// <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;
            }
        }
 /// <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;
 }
Example #16
0
        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);
        }
Example #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.
        }
Example #18
0
        public void StripTargetInvocationExceptionByDefault()
        {
            TargetInvocationException wrapper = new TargetInvocationException(_exception);

              RaygunMessage message = _client.CreateMessage(wrapper);
              Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
        }
Example #19
0
        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);
        }
        /// <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;
        }
Example #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);
            }
        }
    }
Example #22
0
		private static void HandleException(ref RunningResults results, TargetInvocationException ex)
		{
			HandleInnerException(ref results, (dynamic)ex.InnerException);
		}
Example #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);
        }
        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));
            }
        }
Example #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);
        }
 /// <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)
 {
 }
 internal static string FormatTargetInvocationException(TargetInvocationException exception)
 {
     var i = exception.InnerException;
     return String.Format("(threw {0})", i.GetType().Name);
 }
Example #28
0
 public static string DisplayMessage(System.Reflection.TargetInvocationException exception)
 {
     throw null;
 }
Example #29
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)
 {
     Exception_InternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] {});
     return ex.InnerException;
 }
Example #30
0
 public void Error(TargetInvocationException ex)
 {
 }
 private Exception InnerExceptionWhilePreservingStackTrace(TargetInvocationException e)
 {
     internalPreserveStackTraceMethod.Invoke(e.InnerException, new object[0]);
     return e.InnerException;
 }
 /// <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);
 }
Example #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);
        }
 static string FormatTargetInvocationException(TargetInvocationException exception)
 {
     var i = exception.InnerException;
     return string.Format("{0}: {1}", i.GetType().Name, i.Message);
 }
Example #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;
        }
Example #36
0
 private static Exception TranslateException(TargetInvocationException e)
 {
     return new TargetMethodException(e.InnerException);
 }