You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Version Used:
Visual Studio 2017
LanguageVersion: C# 7.2
Steps to Reproduce:
Compile program in DEBUG with 'x1' or 'x2' uncommented:
namespace PeVerifyBug
{
class Program
{
static void Main(string[] args)
{
}
}
public class TestClass
{
private readonly TestStruct _readonlyValue = new TestStruct(42);
public TestStruct Value
{
get
{
//var x1 = _readonlyValue.X;
//var x2 = _readonlyValue.XX;
return default(TestStruct);
}
}
}
public struct TestStruct
{
public readonly float X;
public TestStruct(float x)
{
X = x;
}
public float XX => X;
}
}
Run PE-Verify on the result assembly
I used the one from "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.1 Tools"
-> Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.0
Expected Behavior:
pe verifier should not complain.
Actual Behavior:
if 'x1' was uncommented, pe verifier complains about:
[IL]: Error: [C:\Users\xxxx\source\repos\PeVerifyBug\PeVerifyBug\bin\Debug\PeVerifyBug.exe : PeVerifyBug.TestClass::get_Value][offset 0x00000002] Cannot change initonly field outside its .ctor.
if 'x2' was uncommented, pe verifier doesn't complain.
Relates to #21269 and #22772
The C# compiler sometimes emit unverifiable code (by current PEVerify rules). This can happen when using new features, or when re-compiling existing code with LangVersion >= 7.2. In the latter case, a feature flag can be set in the project to restore the non-optimized behavior (if you prefer that).
Version Used:
Visual Studio 2017
LanguageVersion: C# 7.2
Steps to Reproduce:
I used the one from "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.1 Tools"
-> Microsoft (R) .NET Framework PE Verifier. Version 4.0.30319.0
Expected Behavior:
pe verifier should not complain.
Actual Behavior:
[IL]: Error: [C:\Users\xxxx\source\repos\PeVerifyBug\PeVerifyBug\bin\Debug\PeVerifyBug.exe : PeVerifyBug.TestClass::get_Value][offset 0x00000002] Cannot change initonly field outside its .ctor.
Analyzing the il code
Additional information
When using LanguageVersion: C# 7.1 both cases work
so I think this is a compiler bug and not a problem of PE verify.
The text was updated successfully, but these errors were encountered: