Reputation: 3491
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?
Upvotes: 3
Views: 3874
Reputation: 2695
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.
Upvotes: 1
Reputation: 3491
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
Upvotes: 3