Bug 30692

Summary: CSharpCodeCompiler.CompileAssemblyFromFile returns false compilation error
Product: [Mono] Class Libraries Reporter: Kai Bösefeldt <kai.boesefeldt>
Component: SystemAssignee: Bugzilla <bugzilla>
Status: NEW ---    
Severity: normal CC: kai.boesefeldt, mono-bugs+mono
Priority: ---    
Version: 4.0.0   
Target Milestone: Untriaged   
Hardware: PC   
OS: Linux   
Related Links: https://bugzilla.xamarin.com/show_bug.cgi?id=33896
Tags: Is this bug a regression?: ---
Last known good build:

Description Kai Bösefeldt 2015-06-02 16:11:58 UTC
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.
Comment 1 Kai Bösefeldt 2015-09-11 14:38:54 UTC
I just entered bug 33896 and I think, that both have the same root cause, related to the locate (de_DE.utf8) which makes the streams generate the BOM.