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 (show other bugs)
Version: 4.0.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-06-02 16:11 UTC by Kai Bösefeldt
Modified: 2015-09-11 14:40 UTC (History)
2 users (show)

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


Attachments

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(
    GetCompilerParameters(project),
    project.GetSourcePaths().ToArray());

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.

Note You need to log in before you can comment on or make changes to this bug.