Convert to web application error - could not parse aspx file - asp.net

I occasionally get errors in my aspx files which are caused by problems with the designer file. When this happens I delete the designer file, right click on the aspx file and select "Convert to Web Application".
Usually regenerating the designer file works perfectly, however sometimes I get an error which simply says "Could not parse the file pathToFile.aspx". When this happens there are no useful errors displayed in the error panel which would indicate what the problem is.
I got this error a little while ago, did some searching and found a blog which explains how to get round this problem. It suggests closing the file, cleaning the project, rebuilding then tring again. VS should now give you a more useful error message which pinpoints the problem. This has worked for me in the past, but doesn't work all the time.
Has anyone found a better way of identifying the problem in the aspx file when the "Could not parse file" error is displayed?

I've still not managed to find out why this problem is occurring. VS just seems to be tying itself in knots. However I have found another solution which works when the solution mentioned in my question does not. Simply copy the aspx and code behind into notepad, delete the files from your project, recreated them and copy the code back in. Why does this work? I have no idea

This call is old, but here is a solution if someone else finds this. I had the same problem migrating an AspX app from VS2008 to VS2015. Not all the files migrated. Make sure ALL files have namespaces, and that the name space is references correctly in the aspx file.
Right click on the project select unload project
In windows explorer, create a new file for every file that did not migrate, my example MyForm.aspx, call this file MyForm.aspx.designer.cs
The file must contain the following:
namespace MyProject.pages
{
public partial class MyForm
{
}
}
Save the file and edit the project file (MyProject.csproj) find the entry for your form
<Compile Include="pages\MyForm.aspx.cs">
<DependentUpon>MyForm.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
And under it link the new design file:
<Compile Include="pages\MyForm.aspx.designer.cs">
<DependentUpon>MyForm.aspx</DependentUpon>
</Compile>
Do this for all the files that would not convert. Once completed reload the project and for each file open the markup, add a space, and save. VS will parse the file and store the contents in the designer.

Related

how to edit a file in an online aspx site?

I'm very new to asp.net ( but an aged PHP developer) ..
I'm now in a situation where I should do some small modification in an online aspx script(using vb.net).
I downloaded the whole site and opened it in visual studio, all the modification I had to do is to make a redirect to another external page after succesful login,I determined the place where I should do my modification inside a file named login.aspx.vb , and added this line in it:
Response.Redirect("My URL Here")
And then uploaded only the modified file again, to get no change at all.
I even tried to modify the success msg that appear after successful login and re-uploaded it to find no change at all ( still showing the old message)
Is there some step I'm missing before uploading the page?
You will need to compile the project, and if using visual studios you can just hit ctrl shift B and it will build the entire solution. Visual studio detects which project in the solution has changed and will compile it. Then do as the other answerer says and upload the .dll file which is a container of your compiled code that will be referenced by the host you upload it to when there is a request for it. (A container is a definite over simplification for more details check:
What is a dll?
In ASP.NET there are two types of projects.
Web application project
Web site project
In the first case, when you edit a .vb file you need to compile it with Visual Studio and upload the generated .dll file created in the bin folder.
In the second case you can edit the .vb files and upload them and IIS will compile them.
Based on what you wrote, you are in the first case. In that case you need to have the project / solution files to make any modifications in the .vb files. If you don't have access to those files you could inject some code in the .aspx or .ascx files.
For example:
<%
Dim flag As Boolean = false
// Write some code to set the flag
If (flag) Then
Response.Redirect("~/default.aspx")
End If
%>
Using <%....%> you can write code to execute when the page starts to render. This is a bad practice since because it has poor performance since the code is parsed and executed at runtime, while the code in .cs files is already compiled.
But if you don't have the project files you could do minor changes with this hacky approach.
Edit: If you are in the first scenario, you need to build the project and then upload its .dll file which is in the /bin folder. For any changes in the code files you upload only the .dll. If you change the .aspx, .ascx, etc files you need to upload those as well

Modifying ASPX.CS file has no effect

One of my colleagues maintains a legacy ASP.NET site. Today she bumped into a strange problem:
There is an ASPX page, which throws an exception.
If she deletes the line of the ASPX.CS file which throws the exception, the exception remains (with the same call stack). I'm sure she modified the very same file the calls stack refers to.
If she renames the ASPX.CS file, the server says the file is missing.
If she restarts the server after modifying the ASPX.CS, the exception remains.
If she modifies other ASPX.CS files, she gets the expected effect.
She doesn't compile the page into DLL.
AFAIK IIS should recompile the file when its content changes (MSDN), but this mechanism doesn't work in this case. What should we do? Thanks for your help in advance.
Check to see if the website is a website or web application. Web applications compile all the code behind into DLLs and place them into the 'bin' folder. In order to make changes to the code available, you would have to 'build' the application in VS.
If it is not a compiled web application, then she should check to see if the front end page is pointing to the correct code behind page. Sometimes if you manually copy and rename files, this piece could be left pointing to the original page, not the new .cs file.

Compiler Error Message: CS0433: The type 'MasterPage' exists in both 'c:\~\App_Web_ogmril5q.DLL' and 'c:\~\App_Web_ogmril5q.DLL'

I have 2 master pages inside one ASP.Net website. It work fine without publishing website. After publishing the website on the web server, one of the master pages works fine, but when I want to access the page that is linked with the second master page it gives me the above error. But the weird thing is that the error paths are in c\ drive of my computer.
When this has happened in the past [rare but I saw it once in production] you need to clear out the contents of your shadow copy folders for your application. These are usually in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files but the error path in your exception details will tell you where.
when copying one web page/user control to create another web page/User Control . After copying one userControl to create another, I neglected to change the partial class name in the .cs of the new userControl and the 'Inherits=' in the .aspx file. Fixing those class names stopped the error from occurring. I suppose the easiest fix to avoid this is to just create new userControls each time using the wizard rather than copying and pasting an existing userControl.
as ex
if we copied the main master page to create another master page, both of them will have the same inherit and that what would create the problem so change the class name and then change the inherit with the new class name or always add new items rather than copy and paste
There are various cs0433 errors that can cause this to occur.
Basically, if you like I did, try and compile the same project with different versions of Visual Studio, they may likely use a different version of the .Net Compilers and libraries.
Therefore, some built assemblies will be duplicated causing differing pointers to the same functionality, but with varying .Net CLR's
What solved it for me, was to recreate the folder from "Virgin Code Files", but with a slightly different name such as "Project1", "Project2", etc..
Then you can rebuild the project from scratch with the correct Visual Studio version, which for me was VS2019 and then "Bob's your uncle :)" No more errors.
Please accept this answer

Compile asp.net web site and certain references are not being copied to Temporary ASP.NET Files Folder

Scenerio: I have an asp.net website that I am compiling successfully but keep getting an error in the browser saying that it can not find a referenced dll in the solution. I checked the directory in the Temporary ASP.NET File location and all of my referenced dll's are there except for the one it is failing to retrieve. I manually added the location it was looking for and the site worked.
The dll is referenced in code so it should have been moved to the temp folder. Does anyone have any idea why this would happen? I checked the properties on the referenced dll and copy local is set to true so it should be moved to the output directory.
Right click on the DLLs in your References/Bin directory in your project and look at the Copy Local property. Make sure they are set to True.
After hours of searching google and finding nothing, I decided to take a look at the actual properties of the dll file. To my surprise the issue ended up being permissions. For some reason the one dll that was beating me up all day needed correct permissions to be moved to the output folder. ughhh.
When you say "referenced in code" do you mean it's listed in the project file's Reference section? Or do you mean you are manually referring/naming it in your source code?
Have you tried this in your web.config (or higher up the config chain?)
<hostingEnvironment shadowCopyBinAssemblies="false" />
Where exactly are you expecting it to be copied? What is the path the error message is reporting?

Error Connecting to Undo Manager of Source File XYZ

I've been getting an error recently while debugging an ASP.NET application in Visual Studio 2008:
'Error connecting to undo manager of source file XYZ'
Any idea how I can get rid of the error?
Even simpler:
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.
Found on That One Developer Blog and it worked perfectly for me.
Wouldn't you know it; just after I post this I find a workaround in Scott Hanselman's Blog, in the comments:
1) Right-click the designer file and select delete
2) Right-click the aspx file and select Convert to Web Application
Thanks to Matthew, whomever you are.
I have face the same problem. And I solved it by exclude this file from project and rebuild solution. Then include this file again...DONE!
GOOD LUCK!
I faced the same error now. I had to just open the designer file while editing the aspx file and once done, save both. You don't even have to type any text in the designer. That did the trick!
this one has worked for me:--
"Open desiner.cs file Type some text in it Delete the text you have typed. Save and build the application"
Thanks a lot Jitendra Kumar!!
Open desiner.cs file
Type some text in it
Delete the text you have typed.
Save and build the application.
*** I know this is an old question, and already answered but i'am adding my answer , hopefully it would help someone
In my case the referred file was .cs class, and since there is no .desiner.cs file, i needed another solution
so the solution for my case was to navigate tho the solution folder in windows explorer and delete the .suo file , reopen the solution and rebuild
Closing the solution and deleting the Temporary ASP.Net files directory fixed this for me. [link]
I got this error when i double clicked an asp.net button by mistake and removed it afterwords in the aspx file and .cs file but not in the Designer.cs file. Make sure all the three got files got updated.

Resources