Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ASP.NET "Compiler Error Message: CS1002: ; expected" on the most basic code

Tags:

asp.net

I'm trying to test if ASP.NET is working on my customers IIS 7.5 server, the code below works fine on my server.

<html>
<body bgcolor="yellow">
<center>
<h2>Hello</h2>
<p><%Response.Write(now())%></p>
</center>
</body>
</html>

Using the exact same text.aspx file containing the above code he gets the error:

Compilation Error 
Description: An error occurred during the compilation of a resource required to 
service this request. Please review the following specific error details and 
modify your source code appropriately. 

Compiler Error Message: CS1002: ; expected

Source Error:

    Line 3:  <center>
    Line 4:  <h2>Hello</h2>
    Line 5:  <p><%Response.Write(now())%></p>
    Line 6:  </center>
    Line 7:  </body>

Source File: c:\inetpub\wwwroot\myapp\test.aspx    Line: 5 

Any ideas why this would be? His server will be running a Swiss version of Windows (if that makes any difference).

Many many thanks. Steven

like image 764
Steve Wood Avatar asked Oct 18 '10 15:10

Steve Wood


2 Answers

Your problem is with the following line:

<p><%Response.Write(now())%></p>

The statement needs a semicolon since you're strictly writing a C# statement (rather than using any of the binding expressions):

<p><% Response.Write(now()); %></p>

Whoops...missed part of the question.

If this is working on your local server but not the client's remote server, you should make sure that the client's remote server is set to use Visual Basic instead of C# as the language.

You can also add the Language directive directly to the *.aspx page to force the page to use the correct language:

<%@ Page Title="Your page's title" Language="VB" %>
like image 129
Justin Niessner Avatar answered Oct 06 '22 01:10

Justin Niessner


Check the default language setting in IIS Manager. I think you will find your local machine is set to Visual Basic and the remote server will be set to C#.

IIS 7 and later

  1. Select the web site in question
  2. Select .NET Compilation
  3. Compare the setting value for 'Default Language'

Basically your statement is Visual Basic.

<%= Response.Write("Blah") %>

This is the same statement in C#

<%= Response.Write("Blah"); %> 
like image 28
David Christiansen Avatar answered Oct 06 '22 00:10

David Christiansen