This project is read-only.
3

Resolved

obj?.decimalField ?? 0 gives compiler error: ReadFile on pipe failed -or- error MSB6006

description

When building my Web Application in VS 2015 Preview, I get the error
1>------ Rebuild All started: Project: MyProject, Configuration: Debug Any CPU ------
1>CSC : Internal Compiler Client error : ReadFile on pipe failed The pipe has been ended.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
And in CTP 5, the error is still there, but manifests instead as:
1>------ Rebuild All started: Project: MyProject, Configuration: Debug Any CPU ------
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.CurrentVersion.targets(383,9): error MSB6006: "csc2.exe" exited with code 13435564.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
I was able to determine that the issue is caused by a very specific C# 6.0 construction that I use in two places in my source. I isolated it completely, so that even the very small example shown below exhibits the bug (for me, and hopefully for you; if not, let me know and I can provide my full solution source if need be):
    public sealed class MyType
    {
        public decimal MyField;
    }

    public static decimal MyMethod(MyType myObject)
    {
#if !VS2015_BUGGY
        return myObject?.MyField ?? 0m;     // this fails, but believe it or not....
#else
        return myObject?.MyField ?? 0.0m;   // ...this succeeds! (as do pre-C# 6.0 rewrites)
#endif                                      // (myObject?.MyField).GetValueOrDefault() works too
    }
The bug in the compiler seems to concern only Nullable<Decimal> operator ?? when used after a ?. operator and (amazingly!) only when the right side of the ?? operator is zero, and only when that value of zero is specified as any of 0, 0m, default(decimal), default(int), or a const that has been set to any of those (or other equivalents, of course, like 0x0, etc.). Why 0.0m works (as does any non-zero value, seemingly), your guess is better than mine!

I hope this helps in getting the error addressed so that VS2015 is free of it. If I can be of further assistance, let me know.

comments

rog1039 wrote Jan 2, 2015 at 9:23 PM

Awesome, thanks for posting this. I just ran into the same error and wasn't sure what caused it. Your workaround allowed me to compile and keep working.

Thanks,
Paul

angocke wrote Jan 9, 2015 at 8:39 AM

Fixed in changeset 505b888f56f7408ab117b8f9a1bd767c804cd75c