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

Windows Form designer does not save changes #180

Closed
MikeJohnsonDev opened this issue Nov 6, 2015 · 22 comments
Closed

Windows Form designer does not save changes #180

MikeJohnsonDev opened this issue Nov 6, 2015 · 22 comments
Assignees
Milestone

Comments

@MikeJohnsonDev
Copy link

Hi,

I am facing a problem where the Windows Form designer does not save changes and resets the form back to the previous state.

This only occurs after the first debugging session. If I disable the CodeMaid extension it works perfectly.

I am using Visual Studio 2015 on Windows 10 x64.

Thanks.

@codecadwallader
Copy link
Owner

Thanks for reporting the issue. Unfortunately I have been unable to reproduce it so far.

Some additional information that may help:

  • CodeMaid version
  • Code excerpt/file (if applicable)
  • Steps to reproduce
  • Was this working as expected with a different version?
  • Any additional notes, images, etc.

@MikeJohnsonDev
Copy link
Author

  • CodeMaid version: 0.8.1
  • Steps to reproduce:
  1. Create a new Windows Form project
  2. Add a button (or any other control) to Form1
  3. Save
  4. Right-click the form and select "View Code"
  5. Close Design tab
  6. Right-click the code and select "View Designer"
  7. Copy and paste the previously added control
  8. Save
  9. Repeat steps 5 and 6
  10. The second control has gone

No matter what I do from then on, any changes, whether they are property changes or adding controls, will not be preserved.

I don't know if it worked with a different version, sorry. :)

@codecadwallader
Copy link
Owner

I've had difficulty reproducing this consistently, but I have seen it twice now. Investigating..

@codecadwallader
Copy link
Owner

I have a hunch.. can you please try disabling the following CodeMaid option, and let me know if you are still able to reproduce the issue?

Remove->"Remove end of file trailing new line"

Once I disabled this setting, I was no longer able to reproduce the issue. That same setting has a known workaround for C++ resource files and I'm wondering if the same is needed for VB.

@MikeJohnsonDev
Copy link
Author

I am using C#, does this matter?

@codecadwallader
Copy link
Owner

That's good to know.. not sure why I got VB in my head. Same question still applies though, does removing that setting resolve the issue for you?

@MikeJohnsonDev
Copy link
Author

I disabled "Remove end of file trailing new line". The issue still occurs.

@codecadwallader
Copy link
Owner

How reliably are you able to reproduce it? I saw it about half the time with VB, and never with C#.

If you can consistently see the issue, here's what you could do to help isolate the issue:

Export your CodeMaid settings.
Disable different cleanup actions (e.g. Remove unused using statements)
Repeat the steps above.

That's the approach I took that took me to a specific setting with VB which I'll continue to investigate. When you're done you can import your settings to get back to a clean slate.

In particular I would recommend focusing on the 'Visual Studio' configuration options followed by the 'Remove' cleanup actions.

@MikeJohnsonDev
Copy link
Author

I can reproduce it every time. I'll try to find the culprit setting.

@MikeJohnsonDev
Copy link
Author

Hmm, well, that's interesting. I reset to defaults in CodeMaid and set it up again and now it's working perfectly.

I have attached my old and new settings.
CodeMaid.config.txt
OldCodeMaid.config.txt

@codecadwallader
Copy link
Owner

Resetting to defaults would have turned off automatic cleanup on save. I bet with that disabled you won't see any issues as CodeMaid won't be running a cleanup as the designer saves updates.

@MikeJohnsonDev
Copy link
Author

I turned it back on after I reset.

@MikeJohnsonDev
Copy link
Author

I have no idea what it was (maybe something from an older version?).

@MikeJohnsonDev
Copy link
Author

I have found the culprit: Reorganizing->"Run reorganize at start of cleanup".

Once I enable it, designer changes are not preserved. Disabling it allows changes to be saved.

@codecadwallader
Copy link
Owner

That makes a lot of sense, thanks for discovering it. I should be able to look at it further over the holiday weekend.

@codecadwallader
Copy link
Owner

Unfortunately even with importing your old settings I'm still unable to reproduce the issue. Re-reading some of the original comments to see if I'm forgetting anything you mentioned a debugging session on the original report, but it's not in the steps to reproduce. Is that something you found wasn't required to exhibit the issue? I'm following the steps to reproduce as written (e.g. never closing the code window).

@codecadwallader
Copy link
Owner

Closing due to inactivity. Please feel free to comment and we can reopen this issue.

@codecadwallader
Copy link
Owner

Reopening this issue based on additional information provided by @Andy65 on #217

@codecadwallader
Copy link
Owner

I've now reproduced the issue based on the additional information. I've confirmed this issue is tied to the combination of enabling all of the following settings:

  1. Auto cleanup on save
  2. Auto reorganization during cleanup
  3. Remove existing regions during reorganization

These options were all enabled in the OP's settings as well.

The designer file contains a #region Windows Form Designer generated code, so I suspect what is happening is that as requested CodeMaid is removing that region and it is interrupting the form designer's workflow causing changes to be lost.

Investigating further. The .designer.cs file itself shouldn't(tm) be touched based on default cleanup exclusions..

@codecadwallader
Copy link
Owner

Confirmed the .designer.cs file is not being touched by CodeMaid, which is correct behavior as it is listed in the exclusions.

The Form class will contain a default constructor in order to call InitializeComponent. The removal and re-insertion of this region appears to be what interrupts persistence of designer edits.

The list of above settings should also include:
4. Insert regions during reorganization

codecadwallader added a commit that referenced this issue Feb 27, 2016
…ng as an active code view is required for successful cleanup.
@codecadwallader
Copy link
Owner

I've found that this issue occurs when you trigger the save with the designer window active, but not when you trigger the save with the code window active. We generally try to enforce that a code window is open and active as several of the cleanup commands require that to run successfully. It appears that cleanup is running improperly when the code file is in the background or not open at all.

The straight forward fix I've just pushed is that when the designer window is active, saving the file will not cause the code to be cleaned. The code window will have to be active for cleanup to proceed. There wasn't any good way to distinguish the two window types through the API other than by the file caption which is hacky, but functional.

This fix will be present in the next release, thanks again @DarkfireHellspawn and @Andy65 for all the help tracing it down.

@codecadwallader codecadwallader added this to the v0.9.1 milestone Feb 27, 2016
@codecadwallader
Copy link
Owner

This fix is now available in the latest beta here: https://github.com/codecadwallader/codemaid/releases/tag/v0.9.0.2-beta

If anyone has a chance to test and confirm the fix it would be greatly appreciated. If there are any issues please comment and we'll reopen the issue.

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

No branches or pull requests

2 participants