Search code examples
c#asp.netlambdahttphandlerihttphandler

Ambiguous errors "; expected" "unexpected end of declaration"


I have the following code as part of my project. There is other code in there that can be commented out for the purposes of this exchange.

namespace Project.HttpHandlers
{
    public class Web : IHttpHandler
    {
        /// <summary>
        /// Gets a value indicating whether another request can use the 
        /// <see cref="T:System.Web.IHttpHandler"/> instance.
        /// </summary>
        /// <returns>
        /// true if the <see cref="T:System.Web.IHttpHandler"/> instance 
        /// is reusable; otherwise, false.
        /// </returns>
        public bool IsReusable => false;
    }
}

Visual Studio throws an error on the "public bool IsReusable => false;" line stating that "; expected".

When highlighting the intellisense error over the => operator I get "unexpected end of declaration".

If I change it to "public bool IsReusable = false;" the error goes away. I don't entirely know the function of this line and why there is a lambda operator there so I do not want to do that. I do know it is compilable on a coworkers machine and I see it referenced elsewhere on the web.

I seem to be missing a reference or something else in Visual Studio but I cannot find it.


Solution

  • It seems that your coworker is using Visual Studio 2015 and you are using Visual Studio 2013 or earlier to compile the project.

    If you don't want to upgrade your VS version you can replace the lambda expression with

    public bool IsReusable { get { return false; } }
    

    without any side effects.