roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

`CSharpExtractClassCodeRefactoringProvider` throws exception when type members are contained directly in namespace

Open jhinder opened this issue 3 years ago • 0 comments

Version Used: VS 17.3 (Roslyn 4.3.0-3.22401.3)

Steps to Reproduce: Place the editor caret before the void or the int.

namespace N;

void M()
{
}

int P { get; }

Stack trace:

System.InvalidOperationException : Unexpected null - line 91
   at Roslyn.Utilities.Contract.Fail(String message,Int32 lineNumber)
   at Roslyn.Utilities.Contract.ThrowIfNull[T](T value,Int32 lineNumber)
   at async Microsoft.CodeAnalysis.ExtractClass.AbstractExtractClassRefactoringProvider.TryGetMemberActionAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.ExtractClass.AbstractExtractClassRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)

Expected Behavior: The refactoring fails silently (without an exception).

Actual Behavior: Exception and gold bar.

jhinder avatar Aug 10 '22 21:08 jhinder