I have a ASP.NET website written by someone a while ago, I don't think they used VS to build their sites but unfortunately am not sure what they did use.
I open as website and build .. no errors.
As soon as I open up any of the pages or classes the intellisense moans about nearly everything, starting with
Error 25 Statement cannot appear outside of a method body/multiline lambda.
on the using statements but literally errors on everyline. But still builds fine.
Any ideas how I can resolve this? I can still build the site but if I make any real errors I can't tell where they have come from and also I have no intellisense.
Edit-- an example if I open one of the simplest files on the site.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class About : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Master.bodyClass = "about";
}
}
The error list goes straight to 71 Errors on the single file.
Error 26 Syntax error. PATH\about.aspx 1 PATH\ 1
Error 27 Syntax error. PATH\about.aspx 1 PATH\ 1
Error 28 Syntax error. PATH\about.aspx 1 PATH\ 1
Error 29 'Class' statement must end with a matching 'End Class'. PATH\about.aspx 1 PATH\ 1
Error 30 Declaration expected. PATH\about.aspx 1 PATH\ 1
Error 31 Bracketed identifier is missing closing ']'. PATH\about.aspx 1 PATH\ 1
Error 33 End of statement expected. PATH\about.aspx 1 PATH\ 1
Error 34 Syntax error. PATH\about.aspx 1 PATH\ 1
(to include the first 8 errors, have changed removed the project name / path)
It will still build correctly (the errors don't seem to bother the compiler), but makes it very difficult to work with.
EDIT -
line 1 of the aspx file
<%@ Page MasterPageFile="~/master.master" CodeFile="index.aspx.cs" Inherits="About" %>
Had the same problem. None of the solutions here worked for me. My language was already set to C# in the ASPX file and web.config.
The solution in my case seemed to lie in excluding the ASPX & code-behind files, then compiling the project - VS complains about the missing file!
Then including the files back in cleared out the problem.
Visual Studio thinks that your ASPX files are VB.Net rather than C#.
Change the default language in Web.config (<compilation defaultLanguage="C#">
).
To go further, verify that in your .aspx file, the code starts with "<%@ Page Language="C#"..". This manipulation has been described in the answer, but i will notice that it doesn't work IF THE PAGE STARTS WITH COMMENT LINES ! Visual Studio 2010 doesn't verify if the text before the declaration "<%@ Page />" is comment or not.
Example :
<%--<asp:Label Text="This is a comment"></asp:Label>--%>
<%@ Page Language="C#" ... %>
In this example VS 2010 think the page doesn't start at the Page declaration, but at the Label declaration, so, C# code isn't recognized...
Old thread, but none of the above solutions worked for me as it persisted. My fix was to exclude the aspx file from the project entirely and include it again. Not sure why none of the above suggestions didn't work, but Intellisense seems to happy again.
As a side note: If this is a solution attempted by anyone, make sure you have Show All Files
checked in Solution Explorer
, otherwise your file will be hidden once excluded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With