CSC : error CS7038: Failed to emit module

I also had this exception being thrown in VB.NET (Visual Studio 2015 - Pro), and isolated a single line that was causing the error.

In the line of code below, if you define model as an integer, as in:

Dim model as Integer = 2

and then use:

Const N As Integer = model

you will throw the exception.

However, when I modified this to:

Dim N As Integer = model

the exception was not thrown. The Const syntax was legacy code from another program that I rapidly added model to, and constants can't be set to pre-defined integer types.


Got the same error (fresh installation of the VS2015 Enterprise, ASP.NET webforms project .NET 4.0).

After some investigation I've found that there are two DLLs in references which causes this. Both are .Net 2.0 assemblies and both of them obfuscated by Red Gate Smart Assembly 6.5. And the real reason is... obfuscation.

Luckily, these assemblies are mine, so I've tried to build them without using of Smart Assembly - error is gone.

Interesting is that no any errors or warnings shown by Visual Studio before trying to build a project.

Good luck!

EDIT: Updating Smart Assembly to version 6.9 fixed an issue.


As @Andrey reported this does appear to be an issue with obfuscated assemblies that is causing some difficulty for Roslyn. Today I was able to get a live repro of this error and the root cause appears to be the obfuscator is invalidating / corrupting how default parameter values are stored in metadata. When run through ildasm the default values will be displayed as:

.param [3] /* Invalid default value for 0800001F: */

The previous version of the compiler handled this scenario by treating the invalid value as null or default(T). We will be fixing Roslyn to have the same behavior.


Original Snippet:

    private void radButton1_Click(object sender, EventArgs e)
    {
        string perp = radTextBox1.Text;

        int i = 0;
        DataRow arp = ale.Rows[i];
        while (i <= ale.Rows.Count)
        {
            if (ale.Rows[i].Field<>("FullName") = perp)
            {
                arp = ale.Rows[i];
                ale.Rows.Remove(arp);
            }

        }

        i = ale.Rows.Count;
        radLabel1.Text = i.ToString();
    }

Changed this:

    if (ale.Rows[i].Field<>("FullName") = perp)

To This:

    if (ale.Rows[i].Field<String>("FullName") == perp)