The type or namespace name 'var' could not be found in WCF Service Application

You get this error if you try to use var in a class member, e.g.:

public class Foo
{
    var a = 4;
}

var can only be used inside a method, not in classes, fields or method signatures.

See also: Why no var on fields?


I'm taking a wild guess here, but: var may only be used for local variabels (inside a method).

Are you using it to define instance variables?


For my ASP.NET 3.5 project, I had to make sure that I had the 3.5 framework compiler setup in my web.config file like:

<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>
  </compilers>
</system.codedom>

I would imagine its because your targeting a framework before c#4.0. Try to go to your projects properties and set the target framework to 4.0

Tags:

C#

.Net

Wcf

C# 4.0