Reputation: 2436
It seems the universe is against me this week. I have been happily coding away on my ASP.Net application for weeks now without issues. Today I tried to add a textbox to a form, and on saving the form, I received the following error:
Generation of designer file failed: Cannot use a leading .. to exit above the top directory
I googled, but with no luck. I did find a blog post that shows how to add a key into the registry so that Visual Studio logs more detail about these errors, and the following is what shows up in the generated log file:
------------------------------------------------------------- C:\[path to aspx file]\PageName.aspx Generation of designer file failed: Cannot use a leading .. to exit above the top directory. ------------------------------------------------------------- System.Web.HttpException: Cannot use a leading .. to exit above the top directory. at System.Web.Util.UrlPath.ReduceVirtualPath(String path) at System.Web.Util.UrlPath.Reduce(String path) at System.Web.Util.UrlPath.Combine(String appPath, String basepath, String relative) at System.Web.VirtualPath.Combine(VirtualPath relativePath) at System.Web.VirtualPath.Combine(VirtualPath v1, VirtualPath v2) at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath) at Microsoft.VisualStudio.Web.Application.Parser.BeginParse(String virtualPath, String text) at Microsoft.VisualStudio.Web.Application.Generator.UpdateDesignerClass(String document, String codeBehind, String codeBehindFile, String[] publicFields, UDC_Flags flags) -------------------------------------------------------------
And, of course this means that there is no way I can reference the newly added text box from the code behind.
I thought it might be just this page giving the issue, but I have tried three other pages with the same result. I haven't changed the environment for weeks, so I am not sure how this happens.
Any ideas out there?
Thanks in advance
Hamish
Upvotes: 1
Views: 1177
Reputation: 36
Check the output of the Web project based on your configuration (Release, Debug, ..) and platform (Any CPU, x86, ..).
In my case, this output folder was set to bin/ and after adding a new configuration for x86 platforms this option was set to bin/x86/Debug or bin/x86/Release. And these errors started to appear when adding new files to project.
Upvotes: 0
Reputation: 410
Generation of designer file failed: Cannot use a leading .. to exit above the top directory.
What a wonderful error message!
I had this problem when I clicked on the designer view of a web user control in VS 2010. In my case I noticed that the ascx file icon was showing a blue mark in the bottom left corner. I clicked on the properties and found that the files (ascx, ascx.cs and ascx.cs.designer.cs) were not in the project path but on my desktop.(I don't know how that happened)
This seemed to line up with the usual cryptic MS error message relating to directory.
To fix this I removed the files from the project (ascx, ascx.cs and ascx.cs.designer.cs) then added a new Web User Control to the project with the required name and copied the contents back in from the files on my desktop.
So check your file paths if you see this error message.
Upvotes: 2
Reputation: 61
Change the solution configuration from Release to Debug.
It's working now for me.
Upvotes: 1
Reputation: 2436
For anyone that has the same problem in the future, here is what caused it...
When debugging the application, instead of using VS's built in web server, I was using IIS. For some reason, this caused the above error. I changed the app to use the built in web server, ran it, and then reverted it back to the IIS settings, and all was good.
Not sure why it happened, perhaps something went a little haywire in the plumbing. I'm just glad its back and working.
Upvotes: 2