Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExtractMethodCodeRefactoringProvider threw "System.InvalidOperationException : Failed to compare two elements in the array" #24967

Closed
davkean opened this issue Feb 21, 2018 · 2 comments
Labels

Comments

@davkean
Copy link
Member

davkean commented Feb 21, 2018

Was editing something in this code, I'm not sure what caused it:

using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.Setup;
using WillowDepends.Lib;
using static System.Console;

namespace WillowDepends.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var manifest = Manifest.FromManifestFile(@"\\cpvsbuild\Drops\VS\d15.6\products\27420.00\VisualStudio.vsman");

            foreach (var workload in manifest.Workloads)
            {
                if (!Contains461(manifest, workload))
                {
                    PrintPackageDependencies(manifest, workload);
                }
            }
        }

        private static bool Contains461(Manifest manifest, IPackage workload)
        {
            var alreadySeenPackages = new List<string>();
            bool PringPackage(IPackage package, int v)
            {
                if (alreadySeenPackages.Contains(package.Id.ToLower()))
                {
                    return false;
                }

                alreadySeenPackages.Add(package.Id.ToLower());
                for (int i = 0; i < v; i++)
                {
                    if (package.Id == "Microsoft.Net.PackageGroup.4.6.1.Redist")
                        return true;
                }

                foreach (var dependency in package.Dependencies)
                {
                    if (PringPackage(manifest[dependency.Id], v + 2))
                        return true;
                }

                return false;
            }

            alreadySeenPackages.Add(workload.Id.ToLower());
            
            foreach (var dependency in workload.Dependencies)
            {
                if (PringPackage(manifest[dependency.Id], 4))
                    return true;
            }

            return false;

        }

        static void PrintPackageDependencies(Manifest manifest, IPackage workload)
        {
            var alreadySeenPackages = new List<string>();
            void PringPackage(IPackage package, int v)
            {
                if (alreadySeenPackages.Contains(package.Id.ToLower()))
                {
                    return;
                }

                alreadySeenPackages.Add(package.Id.ToLower());
                for (int i = 0; i < v; i++)
                {
                    Write(" ");
                }
                Write(package.Id);
                Write(Environment.NewLine);
                foreach (var dependency in package.Dependencies)
                {
                    PringPackage(manifest[dependency.Id], v + 2);
                }
            }

            alreadySeenPackages.Add(workload.Id.ToLower());
            WriteLine(workload.Id);
            //foreach (var dependency in workload.Dependencies)
            //{
            //    PringPackage(manifest[dependency.Id], 4);
            //}
        }
    }
}

Resulted in:

System.InvalidOperationException : Failed to compare two elements in the array. ---> System.InvalidOperationException : Shouldn't reach here
   at Roslyn.Utilities.Contract.FailWithReturn[T](String message)
   at Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.ParameterVariableSymbol.CompareTo(IMethodSymbol left,IMethodSymbol right)
   at Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.ParameterVariableSymbol.CompareTo(ParameterVariableSymbol other)
   at Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.ParameterVariableSymbol.CompareTo(VariableSymbol right)
   at Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.VariableSymbol.Compare(VariableSymbol left,VariableSymbol right,INamedTypeSymbol cancellationTokenType)
   at Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.VariableInfo.<>c__DisplayClass24_0.<SortVariables>b__0(VariableInfo v1,VariableInfo v2)
   at System.Array.FunctorComparer`1.Compare(T x,T y)
   at System.Collections.Generic.ArraySortHelper`1.InsertionSort(T[] keys,Int32 lo,Int32 hi,IComparer`1 comparer)
   at System.Collections.Generic.ArraySortHelper`1.IntroSort(T[] keys,Int32 lo,Int32 hi,Int32 depthLimit,IComparer`1 comparer)
   at System.Collections.Generic.ArraySortHelper`1.IntrospectiveSort(T[] keys,Int32 left,Int32 length,IComparer`1 comparer)
   at System.Collections.Generic.ArraySortHelper`1.Sort(T[] keys,Int32 index,Int32 length,IComparer`1 comparer)
   --- End of inner exception stack trace ---
   at System.Collections.Generic.ArraySortHelper`1.Sort(T[] keys,Int32 index,Int32 length,IComparer`1 comparer)
   at System.Array.Sort[T](T[] array,Int32 index,Int32 length,IComparer`1 comparer)
   at System.Collections.Generic.List`1.Sort(Comparison`1 comparison)
   at Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.VariableInfo.SortVariables(Compilation compilation,List`1 list)
   at Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.Analyzer.GetMethodParameters(ICollection`1 variableInfo)
   at Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.Analyzer.GetSignatureInformation(DataFlowAnalysis dataFlowAnalysisData,IDictionary`2 variableInfoMap,Boolean isInExpressionOrHasReturnStatement)
   at async Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.Analyzer.AnalyzeAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.ExtractMethodAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.ExtractMethod.AbstractExtractMethodService`3.ExtractMethodAsync[TValidator,TExtractor,TResult](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod.ExtractMethodCodeRefactoringProvider.GetCodeActionAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod.ExtractMethodCodeRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

I do not know what the repro is.

@jcouv jcouv added the Area-IDE label Feb 21, 2018
@josefpihrt
Copy link
Contributor

maybe a duplicate of #23175

@davkean
Copy link
Member Author

davkean commented Feb 23, 2018

@josefpihrt Yep, I agree, closing in lieu of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants