-
Notifications
You must be signed in to change notification settings - Fork 4k
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 crashed with InvalidOperationException #19136
Comments
Might have something to do with a field and a variable with the same name; "pane". |
I had the `pane' in 'ref pane' selected, I've marked it with '$' and '$'. |
So the issue here is the double-declaration of When this code runs through the method extraction analyzer (modified to avoid the crash), the data flow analysis determines that the out variable is declared but never used (because references later bind to the parameter), and thus can be removed by the method extraction. If this were allowed to proceed, it would totally break the code, producing the following: public static void ActivatePane(this IVsOutputWindow outputWindow, Guid pane)
{
Requires.NotNull(outputWindow, nameof(outputWindow));
Requires.NotEmpty(pane, nameof(pane));
HResult hr = GetHr(outputWindow, ref pane);
if (!hr.IsOK) // Pane not found
return;
hr = pane.Activate();
if (hr.Failed)
throw hr.Exception;
}
private static bool GetHr(IVsOutputWindow outputWindow, ref IVsOutputWindowPane pane)
{
return outputWindow.GetPane(ref pane, out IVsOutputWindowPane pane);
} |
For now I think I'm just going to disable the refactoring for this case, and we can work on improving (expanding) its functionality for a future release. |
What's causign the InvalidOperationException? |
@CyrusNajmabadi Variable matrix doesn't know what to do with a variable which is both passed into the method and also defined by the method. |
VS Build: 26426.1 VSUWPT
Note same code that crashed: #19135.
The text was updated successfully, but these errors were encountered: