public static ProductException Create(Application app, int code, bool error, Exception innerException, TypeReference location, string message, params object [] args)
        {
            var e = new ProductException(code, error, innerException, message, args);

            if (location != null)
            {
                var td = location.Resolve();

                if (td.HasMethods)
                {
                    foreach (var method in td.Methods)
                    {
                        if (!method.IsConstructor)
                        {
                            continue;
                        }
                        SetLocation(app, e, method);
                        if (e.FileName != null)
                        {
                            break;
                        }
                    }
                }
            }
            return(e);
        }
        public static ProductException Create(Application app, int code, bool error, Exception innerException, MethodDefinition location, Instruction instruction, string message, params object [] args)
        {
            var e = new ProductException(code, error, innerException, message, args);

            if (location != null)
            {
                SetLocation(app, e, location, instruction);
            }
            return(e);
        }
        public static void SetLocation(Application app, ProductException ex, MethodDefinition method, Instruction instruction = null)
        {
            if (!method.HasBody)
            {
                return;
            }

            if (instruction == null && method.Body.Instructions.Count == 0)
            {
                return;
            }

            if (instruction == null)
            {
                instruction = method.Body.Instructions [0];
            }

            app.LoadSymbols();

            if (!method.DebugInformation.HasSequencePoints)
            {
                return;
            }

            // Find the sequence point with the highest offset that is less than or equal to the instruction's offset
            SequencePoint seq = null;

            foreach (var pnt in method.DebugInformation.SequencePoints)
            {
                if (pnt.Offset > instruction.Offset)
                {
                    continue;
                }

                if (seq != null && seq.Offset >= pnt.Offset)
                {
                    continue;
                }

                seq = pnt;
            }
            if (seq == null)
            {
                return;
            }

            ex.FileName   = seq.Document.Url;
            ex.LineNumber = seq.StartLine;
        }
        static bool ShowInternal(Exception e)
        {
            ProductException mte   = (e as ProductException);
            bool             error = true;

            if (mte != null)
            {
                error = mte.Error;

                if (!error && GetWarningLevel(mte.Code) == WarningLevel.Disable)
                {
                    return(false);                    // This is an ignored warning.
                }
                Console.Error.WriteLine(mte.ToString());

                if (Verbosity > 1)
                {
                    ShowInner(e);
                }

                if (Verbosity > 2 && !string.IsNullOrEmpty(e.StackTrace))
                {
                    Console.Error.WriteLine(e.StackTrace);
                }
            }
            else if (IsExpectedException == null || !IsExpectedException(e))
            {
                Console.Error.WriteLine("error " + Prefix + "0000: Unexpected error - Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new");
                Console.Error.WriteLine(e.ToString());
            }
            else
            {
                Console.Error.WriteLine(e.ToString());
                if (Verbosity > 1)
                {
                    ShowInner(e);
                }
                if (Verbosity > 2 && !string.IsNullOrEmpty(e.StackTrace))
                {
                    Console.Error.WriteLine(e.StackTrace);
                }
            }

            return(error);
        }