Bug 24675 - Mono C# parser encounters a CS0584 internal compiler error when loading a constant from a legal dll
Summary: Mono C# parser encounters a CS0584 internal compiler error when loading a con...
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2014-11-19 14:11 UTC by emoriarty
Modified: 2015-02-06 11:55 UTC (History)
2 users (show)

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

B.dll (2.00 KB, application/x-msdownload)
2014-11-19 14:11 UTC, emoriarty

Description emoriarty 2014-11-19 14:11:39 UTC
Created attachment 8808 [details]

When trying to compile a program using a dll that csc and ILDASM/ILASM consider valid the mono C# compiler encounters an internal compiler error.

The problem appears to be that in the dll's IL representation it is assigning an int16 value to a unit16 static literal and mono does not like this. I do not have access to the original source for the dll and was unable to determine what kind of source or compilation is required to generate the IL that mono errors out on.

using TypeLib;
public class Bar
      public const int FIELD = Foo.CONSTANT;

B.il - IL for the attached B.dll
//  Microsoft (R) .NET Framework IL Disassembler.  Version 4.0.30319.1
//  Copyright (c) Microsoft Corporation.  All rights reserved.
// Metadata version: v2.0.50727
.assembly extern mscorlib
  .ver 2:0:0:0
.assembly TypeLib
  .hash algorithm 0x00008004
  .ver 1:0:0:0
.class public abstract auto ansi TypeLib.Foo
       extends [mscorlib]System.Object
  // Mono doesn't like int16 here
  // If I change it to uint16 the error goes away.
  .field public static literal uint16 CONSTANT = int16(0xFFFF) 

Command Lines - See attached for copy of B.dll
$ /opt/pkg/mono-3.8.0/bin/mcs /t:library /r:B.dll Reproducer.cs
Reproducer.cs(4,36): error CS0584: Internal compiler error: Unexpected error when loading type `TypeLib.Foo'
error CS0133: The expression being assigned to `Bar.FIELD' must be constant
Compilation failed: 2 error(s), 0 warnings

$ csc /t:library /r:B.dll Reproducer.cs
Microsoft (R) Visual C# Compiler version 4.0.30319.18408
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.

Edward Moriarty | Junior Engineer
Coverity | The Leader in Development Testing
Comment 1 Marek Safar 2015-02-06 11:55:13 UTC
Fixed in master

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.

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

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • 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

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.

Related Links: