CSharpCodeCompiler.CompileAssemblyFromFile returns false compilation error

Since the upgrade from mono 3.12 to mono 4.0, using CSharpCodeCompiler.CompileAssemblyFromFile yields an "empty" error (location is (0, 0) and it has empty text) although the compilation is successful. My calling code:

  var result = new CSharpCodeProvider().CompileAssemblyFromFile(

As I debugged into the mono code, I identified the problem: The compiler executable is called from the code and its error output starts with a byte order mark (BOM). This can be observed in the hex representation of the output string containing the two bytes FE and FF (method: CompileFromFileBatch, variable mscOutput). One quick fix, which worked in my case, was declaring a constant containg the BOM string and stripping it in CreateErrorFromString:

  private readonly static string ByteOrderMark = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
  private static CompilerError CreateErrorFromString(string error_string)
    if (error_string.StartsWith(ByteOrderMark, StringComparison.Ordinal))
      error_string = error_string.Substring(ByteOrderMark.Length);
    if (error_string.StartsWith ("BETA"))
      return null;
    if (error_string == null || error_string == "")
      return null;

Pleace notice that the error string only containing the BOM looks like an empty string on first sight in the debugger, but of course is not caught by 'if (error_string == null || error_string == "")'.

However, maybe my fix is wrong and the problem is where the BOM is emitted. However, in the current version on my machine, CSharpCodeCompiler.CompileAssemblyFromFile does not work.

Reference: https://bugzilla.xamarin.com/show_bug.cgi?id=30692