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]);
        }
Exemplo n.º 2
0
        // ValidateNames does Name validation, and ValidateEnums does enum
        // name validation.  Note that both must be called to determine if a
        // property is valid before it is set, but the order is not important.  Hence
        // ValidateNames can be called before writing out a BAML record, and
        // ValidateEnums can be called later after the BAML record has been read.


        /// <summary>
        /// Validate the Name property.
        /// This will throw an exception if the property is an
        /// Name that does not follow the rules of only letters, digits and underscores in
        /// Name names.
        /// </summary>
        internal void ValidateNames(
            string   value,
            int      lineNumber,
            int      linePosition)
        {
            // set the linenumber and position
            _lineNumber = lineNumber;
            _linePosition = linePosition;

            if (value == string.Empty)
            {
                ThrowException(SRID.ParserBadName, value);
            }

            if (MarkupExtensionParser.LooksLikeAMarkupExtension(value))
            {
                string message = SR.Get(SRID.ParserBadUidOrNameME, value);
                message += " ";
                message += SR.Get(SRID.ParserLineAndOffset,
                            lineNumber.ToString(CultureInfo.CurrentCulture),
                            linePosition.ToString(CultureInfo.CurrentCulture));

                XamlParseException parseException = new XamlParseException(message, lineNumber, linePosition);

                throw parseException;
            }

            if (!NameValidationHelper.IsValidIdentifierName(value))
            {
                ThrowException(SRID.ParserBadName, value);
            }
        }
        void RethrowAsParseException(
            string keyString,
            int lineNumber,
            int linePosition,
            Exception innerException)
        {
            string messageWithLineNumber = keyString;

            // Xml exceptions already have line and position, so we don't have to add it again.
            if (innerException != null &&
                !typeof(System.Xml.XmlException).IsAssignableFrom(innerException.GetType()))
            {
                messageWithLineNumber += " ";
                messageWithLineNumber += SR.Get(SRID.ParserLineAndOffset,
                                                lineNumber.ToString(CultureInfo.CurrentCulture),
                                                linePosition.ToString(CultureInfo.CurrentCulture));
            }

            XamlParseException parseException;

            // If the exception was a XamlParse exception on the other
            // side of a Reflection Invoke, then just pull up the Parse exception.
            if (innerException is TargetInvocationException && innerException.InnerException is XamlParseException)
            {
                  parseException = innerException.InnerException as XamlParseException;
            }
            else
            {
                  parseException = new XamlParseException(messageWithLineNumber, lineNumber, linePosition, innerException);
            }

            throw parseException;
        }
        void ThrowExceptionWithLine(string message)
        {
            message += " ";
            message += SR.Get(SRID.ParserLineAndOffset,
                                                 LineNumber.ToString(CultureInfo.CurrentCulture),
                                                 LinePosition.ToString(CultureInfo.CurrentCulture));

            XamlParseException parseException = new XamlParseException(message,
                LineNumber, LinePosition);

            throw parseException;
        }
        // Token: 0x06002389 RID: 9097 RVA: 0x000AD7D8 File Offset: 0x000AB9D8
        internal static bool ShouldReWrapException(Exception e, Uri baseUri)
        {
            XamlParseException ex = e as XamlParseException;

            return(ex == null || (ex.BaseUri == null && baseUri != null));
        }