Bug 30692 - CSharpCodeCompiler.CompileAssemblyFromFile returns false compilation error
Summary: CSharpCodeCompiler.CompileAssemblyFromFile returns false compilation error
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 4.0.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-06-02 16:11 UTC by Kai Bösefeldt
Modified: 2015-09-11 14:40 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 30692 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

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.