Error connecting to undo manager of source file "whatever control/page.designer.cs"

I've run into this problem a couple of times where I get an error that states:
Error connecting to undo manager of source file "MyControl.ascx.designer.cs" (I've seen it with an aspx.designer.cs too.)

I don't know what the cause is, but I have a sneaking suspicion that the culprit in both of my cases was merge operations from source control interactions where, for whatever reason, my designer became out-of-sync or something with its ascx/aspx counterpart.

After searching around the net, it seemed the most popular method of correcting the problem was to delete the designer completely, then run the option to convert the project to a Web Application.

That option didn't sit right with me. I searched on.

I found an article by Scott Hanselman that discussed excluding the designer from the project, recompile, re-include, recompile again. That seemed a much more fitting solution to me; but I wondered if it could be even easier. So I tried an experiment.

My experiment consisted of simply opening the designer.cs file, typing a character somewhere in the file, deleting the new character, saving the file and recompiling.

The problem disappeared for me after that. (I will note that I cleaned the solution and rebuilt it prior to trying this, and that may be a required piece of the solution to the problem, but I would try the simple step first, then add in the clean/rebuild after.)

I'm using Visual Studio 2008 SP1. I hope this helps someone else out there.


Anonymous said...

Rock on! This was the only thing that worked for me after trying several of the other suggestions!

That One Guy said...

Sweet! I'm glad we could help. It is incredibly annoying when that happens. :)

reeta said...

Heaps thanks for such a simple solution.

That One Guy said...

@reeta: I'm glad it worked for you too! Were you able to fix it without cleaning the solution?

Anonymous said...

I use Visual Studio 2005 and I had to delete the .designer.cs file and then right click on the aspx file and choose "Create Web Application" as per 1 of the comments in http://www.hanselman.com/blog/ErrorConnectingToUndoManagerOfSourceFileQuotwhateverDesignerquot.aspx

That One Guy said...

I've also noticed that this happens sometimes when you're editing markup in a page/control (in my case a MasterPage) while debugging.

After stopping debug, completing my edits, going into the designer.cs, adding/deleting the character and saving again, the error went away.

(Again in Visual Studio 2008; not sure if you have to do it the hard way in 2005 as mentioned in the prior comment.)

Anonymous said...

I definitely like this solution best. Thanks for the suggestion!

Shey said...

thx a lot!

Bob C. said...

Thanks for this solution! I too didn't feel comfortable deleting the designer file then converting the project to a web application. Your solution worked perfectly for me the first time and I didn't clean the solution or do anything else prior to attempting it.

That One Guy said...

Nice! I'm so glad this is working for everyone.

I've since discovered that this problem occurs if you edit the ASPX page in regards to adding/modifing/deleting ASP.NET controls in the ASPX page while debugging the site. If you make minor tweaks like attribute changes or style tweaks, etc, you shouldn't see the error.

The behavior is due to the magic of Visual Studio dynamically updating that designer file on-the-fly as you make ASP.NET control-releated changes; it just doesn't seem to handle it well if you're making those changes while in debug mode.

If you simply stop debugging after getting the error, add/delete the character in the offending designer.cs and save, then rebuild, you should be golden every time.

So for future reference, to avoid seeing the error, try not to tweak ASP.NET controls in your ASPX pages while debugging. If you forget, you know how to fix it.

Happy coding!

Naganand Mavnur said...

Worked for me, Thanks