Can C# 3.0 not be used in websites?

R

Rick van der Arend

Hello,

In my (Visual Studio 2008) solution, I am not able to use C# 3.0
features (like the var keyword) in all of my projects. Does anyone
know what could be the reason?

I am working in a solution with an ASP.NET website and several class
library projects. In the class libraries I can use var, however, in
the website I cannot.
Both the website and the class libraries are targeted for the .NET 3.5
platform. I thought that was the problem, but it seems it is something
else..

Other 'oddity' is that we are not including the LINQ dll's. But this
is the same for the website as for the class libraries, so that
shouldn't be the problem.

Any ideas? Thanks in advance!

Kind regards,
Rick
 
R

Rick van der Arend

MC wrote:
What does the error message say?

Well, to be honest I do not get any specific error message. Just a
compiler error you would expect with these language features non-
existant.
 
R

Rick van der Arend

Well, to be honest I do not get any specific error message. Just a
compiler error you would expect with these language features non-
existant.- Hide quoted text -

I've run it again on my dev station at work, just to get the exact
message:
"The type or namespace name 'var' could not be found (are you missing
a using directive or an assembly reference?)"

As you can see, this just is a message that you would expect when
'var' is completely unrecognized..
 
F

Family Tree Mike

Rick van der Arend said:
I've run it again on my dev station at work, just to get the exact
message:
"The type or namespace name 'var' could not be found (are you missing
a using directive or an assembly reference?)"

As you can see, this just is a message that you would expect when
'var' is completely unrecognized..


It really sounds like the only thing to explain this would be that the
server does not have .Net 3.5 installed correctly.

Have you tried precompiling the site before deploying to your server?
 
R

Rick van der Arend

Rick van der Arend said:
It really sounds like the only thing to explain this would be that the
server does not have .Net 3.5 installed correctly.

Have you tried precompiling the site before deploying to your server?

I am talking about a website that I am currently developing, so this
already happens on my workstation, in the development web server. And
I think .NET 3.5 not being installed cannot explain the problem, as my
other assemblies (code libraries) can be written in C#3.0 just the
same.

If I am not mistaken, C#3.0 language features are something the c#
compiler supports. I am not sure if the .NET 3.5 framework libraries
are even necessary for them to be used. But anyhow, .NET 3.5 is
installed and both the website and the code library projects target
the .NET 3.5 Platform. Thanks for the suggestion, though!
 
T

Tom Shelton

I am talking about a website that I am currently developing, so this
already happens on my workstation, in the development web server. And
I think .NET 3.5 not being installed cannot explain the problem, as my
other assemblies (code libraries) can be written in C#3.0 just the
same.

If I am not mistaken, C#3.0 language features are something the c#
compiler supports. I am not sure if the .NET 3.5 framework libraries
are even necessary for them to be used. But anyhow, .NET 3.5 is
installed and both the website and the code library projects target
the .NET 3.5 Platform. Thanks for the suggestion, though!

Hmmm... it sounds to me like the code is being compiled with an older version
of the compiler. var is not a runtime or library thing, it's a C# 3.0
compiler thing.

Not sure how to fix it, but have you checked the version of .NET the website
is using?
 
R

Rick van der Arend

I am talking about a website that I am currently developing, so this
Hmmm... it sounds to me like the code is being compiled with an older version
of the compiler.  var is not a runtime or library thing, it's a C# 3.0
compiler thing.

Not sure how to fix it, but have you checked the version of .NET the website
is using?

If you are talking about the .NET pratform that it is targeting,
that's 3.5
If you are talking about something else, I didn't understand your
question. Is there some place/menu/option/dialog where I can find the
information you are talking about?
 
R

Rick van der Arend

If you are talking about the .NET pratform that it is targeting,
that's 3.5
If you are talking about something else, I didn't understand your
question. Is there some place/menu/option/dialog where I can find the
information you are talking about?

Extra info: on the same dev machine, visual studio, dev web server, I
made a new website, also targeting .NET 3.5 - this one works with C#
3.0 syntax
So it seems to be some setting in the website.
 
T

Tom Shelton

Extra info: on the same dev machine, visual studio, dev web server, I
made a new website, also targeting .NET 3.5 - this one works with C#
3.0 syntax
So it seems to be some setting in the website.

Yes... That's what I was getting at. If you look in the settings for the
website, check the asp.net tab and compare them to the asp.net settings of the
working website.
 
F

Fernando A. Gómez F.

Rick said:
Hello,

In my (Visual Studio 2008) solution, I am not able to use C# 3.0
features (like the var keyword) in all of my projects. Does anyone
know what could be the reason?

I am working in a solution with an ASP.NET website and several class
library projects. In the class libraries I can use var, however, in
the website I cannot.
Both the website and the class libraries are targeted for the .NET 3.5
platform. I thought that was the problem, but it seems it is something
else..

Other 'oddity' is that we are not including the LINQ dll's. But this
is the same for the website as for the class libraries, so that
shouldn't be the problem.

Any ideas? Thanks in advance!

Kind regards,
Rick

Hi there.

FWIW, I had the same problem. I checked my app pool in IIS (I'm running
IIS 7 on Vista) and it was targeting .NET 2.0. However, the only two
options available were .NET 2.0 and .NET 1.1 (although I have .NET 3.5).
Since I wasn't using any .NET 3.5 feature (nor C# 3.0) I changed the
target of my WebSite to .NET 2.0 and be done with it.

Now that you mention this, I think it is more an issue with the IIS.
Don't know how to fix this, but I'd say you should look into IIS settings.

Regards.
 
R

Rick van der Arend

Now that you mention this, I think it is more an issue with the IIS.
Don't know how to fix this, but I'd say you should look into IIS settings.

Hi, thanks for responding. However, I don't think I agree with you on
this one. The C# 3.0 features are something the compiler (csc.exe)
offers. After compilation, the output assembly can be used on the CLR
2.0. Of course, if you use assemblies that are part of the .NET 3.5
framework, those should be present as well. But you might also target
the .NET 2.0 framework only.

So I was looking for a feature to disable C# 3.0 in websites. In
windows forms and web applications it is hidden in an 'advanced'
dialog on the 'build' tab of the project properties. However, for
websites it is not there.

My best guess at the moment (can't get to the original project any
more) is that it was set in the web.config. I found this option in a
standard web.config.

<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>

In the project where I experienced the odd behaviour, CompilerVersion
might have been set to another (lower) value. I cannot say this for
sure, as I have no way of checking it. I also wonder why it would set
this way.

Best regards,
Rick
 
R

Rick van der Arend

Read your post again Fernando and changed my mind. :)

You might be right I guess, because some compilation is (sometimes)
performed just before running a webpage. It might be that the compiler
that comes with the installed framework is used for this compilation
and it might be that a .NET 2.0 installation is used at the production
server. Not sure at all when and how this would influence the
behaviour I observed, but the post I just sent doesn't tell the
complete story, that's for sure. I guess this might have constrained
somebody into configuring the website as to using the c# 2.0 compiler
at the development server and workstations as well.

Kind regards,
Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top