The code below compiles fine in Debug but failed with a CS0136(A local or parameter named 'x' cannot be decaled..) error in Release. Anybody has any idea why the error is not reported in Debug build?
public void test()
{
Action<int> a = x => x++;
int x = 0;
}
Target framework 4.6.1
VS version: 16.4.3 and 16.4.5
MSBuildVersion: 16.4.0
MSBuildRuntimeVersion = 4.0.30319
After some investigation, I was able to trace the error to this configuration difference between debug and release build
Debug build has this line in config, but release build does not have.
<LangVersion>latest</LangVersion>
and this problem can be reproduced with the following two command
csc.exe /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll" /langversion:7.3 Program.cs"
csc.exe /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll" /langversion:latest Program.cs"