Exemple #1
0
        public static void HandleFirstChanceException(object sender, FirstChanceExceptionEventArgs e)
        {
            if (isReentrant)
            {
                return;
            }

            isReentrant = true;
            try
            {
                var ex = e.Exception;

                if (ex is EntryPointNotFoundException)
                {
                    if (ex.Message.Contains("Unable to find an entry point named 'ReadFile'"))
                    {
                        return;
                    }
                }

                if (ex is InvalidCastException)
                {
                    if (ex.Message.Contains("Invalid cast from 'System.String' to"))
                    {
                        return;
                    }

                    if (ex.Message.Contains("Unable to cast object of type 'Microsoft.Build.Tasks.Windows.MarkupCompilePass1' to type 'Microsoft.Build.Framework.ITask'."))
                    {
                        return;
                    }
                }

                if (ex is InvalidOperationException)
                {
                    if (ex.Message.Contains("An attempt was made to transition a task to a final state when it had already completed."))
                    {
                        return;
                    }
                }

                if (ex is AggregateException)
                {
                    return;
                }

                if (ex is DecoderFallbackException)
                {
                    return;
                }

                if (ex is DirectoryNotFoundException)
                {
                    return;
                }

                if (ex is Microsoft.Build.Exceptions.InvalidProjectFileException)
                {
                    return;
                }

                if (ex is FileNotFoundException)
                {
                    return;
                }

                if (ex is MissingMethodException)
                {
                    // MSBuild evaluation has a known one
                    return;
                }

                if (ex is XmlException && ex.Message.Contains("There are multiple root elements"))
                {
                    return;
                }

                if (knownMessages.Contains(ex.Message))
                {
                    return;
                }

                string exceptionType = ex.GetType().FullName;

                if (exceptionType.Contains("UnsupportedSignatureContent"))
                {
                    return;
                }

                string stackTrace = ex.StackTrace;
                if (stackTrace.Contains("Antlr"))
                {
                    return;
                }

                if (stackTrace.Contains("at System.Guid.StringToInt"))
                {
                    return;
                }

                var trace = new TraceFactory().Manufacture(ex);

                if (trace.Select(f => f.Method.Module).Any(IgnoredModules.Contains))
                {
                    return;
                }

                var message = DateTime.Now.ToString() + ": First chance exception";
                if (SolutionGenerator.CurrentAssemblyName != null)
                {
                    message += " while processing assembly: " + SolutionGenerator.CurrentAssemblyName;

                    if (SolutionGenerator.CurrentAssemblyName == "Microsoft.VisualStudio.Diagnostics.ManagedHeapAnalyzerUnitTests" && ex.Message.Contains("The network path was not found"))
                    {
                        // their project file isn't authored correctly but we deal with it well
                        // so just ignore this one
                        return;
                    }
                }

                Log.Exception(ex, message, isSevere: false);
            }
            finally
            {
                isReentrant = false;
            }
        }