Bug 33953 - Some Refactoring does not work
Summary: Some Refactoring does not work
Status: NEW
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Text Editor ()
Version: 5.9
Hardware: PC Linux
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Cody Russell
Depends on:
Reported: 2015-09-15 00:06 UTC by Edgar Carballo
Modified: 2016-11-30 18:47 UTC (History)
5 users (show)

Tags: gtk
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 33953 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Edgar Carballo 2015-09-15 00:06:05 UTC
Description of Problem:

Some refactoring like:
* Implement interface (explicit)
* Implement abstract members
* Create getter/property
are not working

Steps to reproduce the problem:
1. Open the context menu on the right place -> refactoring -> enter 
2. The editor wont do anything.

Actual Results:

Expected Results:
Some code generated

How often does this happen? 

Additional Information:
Happened just after the upgrade 4 days ago.
Comment 1 Mike Krüger 2015-09-15 02:14:50 UTC
Seems a core function is broken on linux.


Doesn't show any dialog and just gives back the cancel message. I suspect some os x/windows special case handling broke it.
Comment 2 Hendrik Belitz 2015-09-17 10:14:21 UTC
I can confirm this, but for me not a single refactoring operation besides a simple rename is working. There is also no message logged that might hint at the error.

I am using monodevelop 5.9.6 (as available in the official repository) on Ubuntu Linux 15.04 x64.
Comment 3 David 2015-10-12 08:38:39 UTC
Same here Ubuntu 15.04 x64

I tried it with 

Version 5.11
	Mono 4.2.1 (Stable Tue Oct  6 14:40:19 UTC 2015) (64-bit)
	GTK+ 2.24.23 (Ambiance theme)


Version 5.10
	Mono 4.2.1 (Stable Tue Oct  6 14:40:19 UTC 2015) (64-bit)
	GTK+ 2.24.23 (Ambiance theme)
Comment 4 David 2015-10-12 08:47:45 UTC
I comiled the 5.11 latest from github and run it. I found this logging message in the console

ERROR [2015-10-12 14:43:48Z]: Error while context menu popup.
System.NullReferenceException: Object reference not set to an instance of an object
   at Mono.TextEditor.GtkWorkarounds.ShowContextMenu (Gtk.Menu menu, Gtk.Widget parent, Gdk.EventButton evt, Rectangle caret) in /home/lala/monodev/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/GtkWorkarounds.cs:line 496
   at MonoDevelop.CodeActions.CodeActionEditorExtension.ShowFixesMenu (Gtk.Widget parent, Rectangle evt, MonoDevelop.CodeActions.FixMenuDescriptor entrySet) in /home/lala/monodev/monodevelop/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs:line 372
Comment 5 Sergey Zhukov 2015-10-25 20:39:50 UTC
This bug is introduced in this commit:

Comment 6 Cody Russell 2015-10-25 21:23:35 UTC
I don't have Linux setup anywhere right now to test this, but I did recently commit a fix that seems relevant to the stacktrace that David posted above.


David, can you confirm if this helped any?
Comment 7 Edgar Carballo 2015-10-25 23:06:50 UTC
I just compiled it (df920cc76875a1723f162006684b210265cd282f above your merge commit) and still seems broken.

I wish I could give more information but the console does not say a thing.
Comment 8 David 2015-10-26 03:03:15 UTC
@Cody Russel: Looks good! It works on my maschine! ;) 

Latest commit df920cc76875a1723f162006684b210265cd282f
Comment 9 Sergey Zhukov 2015-10-26 05:52:44 UTC

The issue in RefactoringService.CheckUserSettings()

				var message = new QuestionMessage (text);
				message.Buttons.Add (useRefactoringsButton);
				message.Buttons.Add (disableRefactoringsButton);
				message.Buttons.Add (AlertButton.Cancel);
				message.Icon = Gtk.Stock.DialogWarning;
				message.DefaultButton = 2;

				var result = MessageService.AskQuestion (message);
					if (result == AlertButton.Cancel) {
					return false;

This piece of code does not show alert window and result always AlertButton.Cancel, so the method CheckUserSettings always returns 'false' and does not allow to do further refactoring
Comment 10 Sergey Zhukov 2015-10-26 06:22:53 UTC
As a workaround you can right click on the solution, remove check near "Enable refactoring" menu item (it is located under "Options" menu item) and then set the check again. After these manipulations refactoring starts work on Linux too.

Unfortunately, "Enable refactoring" checkbox is available only in the latest Monodevelop and does not exist in Monodevelop 5.9.6, but it can be enabled manually.

Go to your solution folder, open <YourSolution>.userprefs file, then add the attribute RefactoringSettings.EnableRefactorings="True" to the first XML element "Properties" the file.

It should look like this 
<Properties StartupItem="...." RefactoringSettings.EnableRefactorings="True">
Comment 11 g 2016-11-01 14:31:07 UTC
ubuntu 14.04.5
Monodevelop 5.10

Has this issue ever been resolved ?

Rename - ok
Goto declaration/Find references ( ... ) - ok
Sort usings - No effect
Implement interface/explicit - No effect
To private/protected/... - No effect
Create getter/property - No effect

'Enable refactoring' item does not exist and Sergey's solution has had no effect.

Is MD 6 required to get the fix ?
Since I need ubuntu 16 to use the 6.1 flatpak install - am I stuck using a buggy MD 5.10  ?
Comment 12 Sergey Zhukov 2016-11-30 15:11:14 UTC
I've just checked the workaround and it still works for monodevelop 5.10. Steps to enable refactoring:

1. Create empty Console project 'testRefactoring', save it and close in monodevelop. You must close the project in monodevelop, or userprefs won't change.
2. Open file testRefactoring.userprefs in any editor
Change the first line from 

<Properties StartupItem="testRefactoring/testRefactoring.csproj">


<Properties RefactoringSettings.EnableRefactorings="True" StartupItem="testRefactoring/testRefactoring.csproj">

3. Open project in Monodevelop.
4. Add new class EmptyClass to the project.
5. Change the inheritance by adding `public class EmptyClass : IDisposable`
6. Make right click on IDisposable choose Refactor/implement interface
7. Refactoring line will appear where you can choose the place in source to add refactor.
8. Hit `enter` and `Dispose` method will be added to the class.

For me using Monodevelop from flatpak is a bad idea, because monodevelop cannot use libraries installed on the system (when the code depends on this libraries using PInvoke, etc) and there is no way to install these libraries into flatpak bundle. It would be better to return monodevelop 6.1 back to linux as a standard linux package as it was before.
Comment 13 g 2016-11-30 18:47:31 UTC
Thanks - that did it - not sure what I was doing wrong the 1st time - must have fat fingered it somewhere.

I am not really familiar with flatpak but it does seem to just introduce one more dependency and it leaves anyone not running on the latest and greatest out in the cold - I am also not clear how this affects mono server installs if at all.