I have an old project that was using .net 4.5 which I have upgraded to .net 4.6.2. I am using visual studio 2017, so it should support lambda expressions, but when I try to run my project it always throws this error:
Invalid token '=>' in class, struct, or interface member declaration
How can I get my project to compile using c# 6? I thought just upgrading the target framework was enough?
By changing the default language version, I started getting another error:
I investigated this and found some answers, which lead me to the correct answer. The only thing I had to do was update the package
Microsoft.Net.Compilers
It was using version 1.3, I upgraded to 2.10.0 and everything worked.
You need to set the Advanced Build Settings most likely
Set the
Language Version
to your favorite or something appropriateTry Adding the reference for Microsoft.Net.Compilers to the said project using Nuget (specific for 2.10 or above) to force compiler bindings to use 4.6+ features.
Invalid token class error usually appears when .Net Compilers are not correctly configured in Project.
Install-Package Microsoft.Net.Compilers -Version 2.10.0
Note: If you're using VS 2017, it should automatically do so.