Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make message of ModuleEmitFailure error more detailed #40180

Merged
merged 5 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4002,7 +4002,7 @@ You should consider suppressing the warning only if you're sure that you don't w
<value>Command line switch is not yet implemented</value>
</data>
<data name="ERR_ModuleEmitFailure" xml:space="preserve">
<value>Failed to emit module '{0}'.</value>
<value>Failed to emit module '{0}': {1}</value>
</data>
<data name="ERR_FixedLocalInLambda" xml:space="preserve">
<value>Cannot use fixed local '{0}' inside an anonymous method, lambda expression, or query expression</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2731,7 +2731,9 @@ internal override bool CompileMethods(
if (moduleBeingBuilt.SourceModule.HasBadAttributes)
{
// If there were errors but no declaration diagnostics, explicitly add a "Failed to emit module" error.
diagnostics.Add(ErrorCode.ERR_ModuleEmitFailure, NoLocation.Singleton, ((Cci.INamedEntity)moduleBeingBuilt).Name);
diagnostics.Add(ErrorCode.ERR_ModuleEmitFailure, NoLocation.Singleton, ((Cci.INamedEntity)moduleBeingBuilt).Name,
new LocalizableResourceString(nameof(CodeAnalysisResources.ModuleHasInvalidAttributes), CodeAnalysisResources.ResourceManager, typeof(CodeAnalysisResources)));

return false;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ public static void CompileMethodBodies(
// module or crashing.
if (moduleBeingBuiltOpt != null && (methodCompiler._globalHasErrors || moduleBeingBuiltOpt.SourceModule.HasBadAttributes) && !diagnostics.HasAnyErrors() && !hasDeclarationErrors)
{
diagnostics.Add(ErrorCode.ERR_ModuleEmitFailure, NoLocation.Singleton, ((Cci.INamedEntity)moduleBeingBuiltOpt).Name);
var messageResourceName = methodCompiler._globalHasErrors ? nameof(CodeAnalysisResources.UnableToDetermineSpecificCauseOfFailure) : nameof(CodeAnalysisResources.ModuleHasInvalidAttributes);
diagnostics.Add(ErrorCode.ERR_ModuleEmitFailure, NoLocation.Singleton, ((Cci.INamedEntity)moduleBeingBuiltOpt).Name,
new LocalizableResourceString(messageResourceName, CodeAnalysisResources.ResourceManager, typeof(CodeAnalysisResources)));
}

diagnostics.AddRange(compilation.AdditionalCodegenWarnings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ internal static EmitDifferenceResult EmitDifference(
edits: edits,
isAddedSymbol: isAddedSymbol);
}
catch (NotSupportedException)
catch (NotSupportedException e)
{
// TODO: better error code (https://github.com/dotnet/roslyn/issues/8910)
diagnostics.Add(ErrorCode.ERR_ModuleEmitFailure, NoLocation.Singleton, compilation.AssemblyName);
// TODO: https://github.com/dotnet/roslyn/issues/9004
diagnostics.Add(ErrorCode.ERR_ModuleEmitFailure, NoLocation.Singleton, compilation.AssemblyName, e.Message);
return new EmitDifferenceResult(success: false, diagnostics: diagnostics.ToReadOnlyAndFree(), baseline: null);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Symbols/ReferenceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private static AssemblySymbol MapAssemblyIdentityToResolvedSymbol(AssemblyIdenti
if (map.TryGetValue(identity, out symbol, (v1, v2, s) => true))
{
// TODO: https://github.com/dotnet/roslyn/issues/9004
throw new NotSupportedException($"Changing the version of an assembly reference is not allowed during debugging: '{identity}' changed version to {symbol.Identity.Version}");
throw new NotSupportedException(string.Format(CodeAnalysisResources.ChangingVersionOfAssemblyReferenceIsNotAllowedDuringDebugging, identity, symbol.Identity.Version));
}

return new MissingAssemblySymbol(identity);
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ Potlačení upozornění zvažte jenom v případě, když určitě nechcete če
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">Nepovedlo se vygenerovat modul {0}.</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ Sie sollten das Unterdrücken der Warnung nur in Betracht ziehen, wenn Sie siche
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">Fehler beim Ausgeben von Modul "{0}".</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7779,8 +7779,8 @@ Considere la posibilidad de suprimir la advertencia solo si tiene la seguridad d
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">No se pudo emitir el módulo '{0}'.</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ Supprimez l'avertissement seulement si vous êtes sûr de ne pas vouloir attendr
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">Échec de l'émission du module '{0}'.</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ Come procedura consigliata, è consigliabile attendere sempre la chiamata.
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">Non è stato possibile creare il modulo '{0}'.</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ You should consider suppressing the warning only if you're sure that you don't w
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">モジュール '{0}' の作成に失敗しました。</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ You should consider suppressing the warning only if you're sure that you don't w
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">{0}' 모듈을 내보내지 못했습니다.</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ Pominięcie ostrzeżenia należy wziąć pod uwagę tylko w sytuacji, gdy na pew
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">Wyemitowanie modułu „{0}” nie powiodło się.</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ Você pode suprimir o aviso se tiver certeza de que não vai querer aguardar a c
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">Falha para emitir o módulo "{0}".</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ You should consider suppressing the warning only if you're sure that you don't w
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">Не удалось выдать модуль "{0}".</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ Yalnızca asenkron çağrının tamamlanmasını beklemek istemediğinizden ve
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">{0}' modülü gösterilemedi.</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ You should consider suppressing the warning only if you're sure that you don't w
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">未能发出模块“{0}”。</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7778,8 +7778,8 @@ You should consider suppressing the warning only if you're sure that you don't w
<note />
</trans-unit>
<trans-unit id="ERR_ModuleEmitFailure">
<source>Failed to emit module '{0}'.</source>
<target state="translated">無法發出模組 '{0}'</target>
<source>Failed to emit module '{0}': {1}</source>
<target state="new">Failed to emit module '{0}': {1}</target>
<note />
</trans-unit>
<trans-unit id="ERR_FixedLocalInLambda">
Expand Down
26 changes: 11 additions & 15 deletions src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8901,10 +8901,9 @@ public static class LanguageNames
";
var compilation1 = CreateCompilationWithMscorlib40(source1, options: TestOptions.DebugDll);
compilation1.VerifyDiagnostics(
// (10,18): error CS0246: The type or namespace name 'xyz' could not be found (are you missing a using directive or an assembly reference?)
// public const xyz CSharp = "C#";
Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "xyz").WithArguments("xyz").WithLocation(10, 18)
);
// (10,18): error CS0246: The type or namespace name 'xyz' could not be found (are you missing a using directive or an assembly reference?)
// public const xyz CSharp = "C#";
Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "xyz").WithArguments("xyz").WithLocation(10, 18));

var source2 =
@"
Expand All @@ -8920,26 +8919,23 @@ internal sealed class CSharpCompilerDiagnosticAnalyzer
var emitResult2 = compilation2.Emit(peStream: new MemoryStream(), options: new EmitOptions(metadataOnly: true));
Assert.False(emitResult2.Success);
emitResult2.Diagnostics.Verify(
// error CS7038: Failed to emit module 'Test.dll'.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("Test.dll").WithLocation(1, 1)
);
// error CS7038: Failed to emit module 'Test.dll': Module has invalid attributes.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("Test.dll", "Module has invalid attributes.").WithLocation(1, 1));

// Use different mscorlib to test retargeting scenario
var compilation3 = CreateCompilationWithMscorlib45(source2, new[] { new CSharpCompilationReference(compilation1) }, options: TestOptions.DebugDll);
Assert.NotSame(compilation1.Assembly, compilation3.SourceModule.ReferencedAssemblySymbols[1]);
compilation3.VerifyDiagnostics(
// (2,35): error CS0246: The type or namespace name 'xyz' could not be found (are you missing a using directive or an assembly reference?)
// [DiagnosticAnalyzer(LanguageNames.CSharp)]
Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "CSharp").WithArguments("xyz").WithLocation(2, 35)
);
// (2,35): error CS0246: The type or namespace name 'xyz' could not be found (are you missing a using directive or an assembly reference?)
// [DiagnosticAnalyzer(LanguageNames.CSharp)]
Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "CSharp").WithArguments("xyz").WithLocation(2, 35));

var emitResult3 = compilation3.Emit(peStream: new MemoryStream(), options: new EmitOptions(metadataOnly: true));
Assert.False(emitResult3.Success);
emitResult3.Diagnostics.Verify(
// (2,35): error CS0246: The type or namespace name 'xyz' could not be found (are you missing a using directive or an assembly reference?)
// [DiagnosticAnalyzer(LanguageNames.CSharp)]
Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "CSharp").WithArguments("xyz").WithLocation(2, 35)
);
// (2,35): error CS0246: The type or namespace name 'xyz' could not be found (are you missing a using directive or an assembly reference?)
// [DiagnosticAnalyzer(LanguageNames.CSharp)]
Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "CSharp").WithArguments("xyz").WithLocation(2, 35));
}

[Fact, WorkItem(30833, "https://github.com/dotnet/roslyn/issues/30833")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ public void FieldInitializerWithBadConstantValueDifferentModule()
compilation1.VerifyDiagnostics(
// (3,27): error CS0133: The expression being assigned to 'B.F1' must be constant
Diagnostic(ErrorCode.ERR_NotConstantExpression, "F2").WithArguments("B.F1").WithLocation(3, 27));

var source2 =
@"class A
{
Expand All @@ -689,8 +690,8 @@ public void FieldInitializerWithBadConstantValueDifferentModule()
CreateCompilation(source2, new[] { new CSharpCompilationReference(compilation1) }, assemblyName: "2110a705-cc34-430b-9450-ca37031aa828")
.Emit(new System.IO.MemoryStream()).Diagnostics
.Verify(
// error CS7038: Failed to emit module '2110a705-cc34-430b-9450-ca37031aa828'.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("2110a705-cc34-430b-9450-ca37031aa828"));
// error CS7038: Failed to emit module '2110a705-cc34-430b-9450-ca37031aa828': Unable to determine specific cause of the failure.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("2110a705-cc34-430b-9450-ca37031aa828", "Unable to determine specific cause of the failure."));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,11 @@ class C
ImmutableArray.Create(SemanticEdit.Create(SemanticEditKind.Update, f0, f1)));

diff1.EmitResult.Diagnostics.Verify(
// error CS7038: Failed to emit module 'C'.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("C"));
// error CS7038: Failed to emit module 'C': Changing the version of an assembly reference is not allowed during debugging:
// 'Lib, Version=1.0.2000.1001, Culture=neutral, PublicKeyToken=null' changed version to '1.0.2000.1002'.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("C",
string.Format(CodeAnalysisResources.ChangingVersionOfAssemblyReferenceIsNotAllowedDuringDebugging,
"Lib, Version=1.0.2000.1001, Culture=neutral, PublicKeyToken=null", "1.0.2000.1002")));
}

[WorkItem(9004, "https://github.com/dotnet/roslyn/issues/9004")]
Expand Down Expand Up @@ -486,10 +489,12 @@ class C
generation0,
ImmutableArray.Create(SemanticEdit.Create(SemanticEditKind.Update, f0, f1)));

// TODO: message should be: Changing the version of an assembly reference is not allowed during debugging
diff1.EmitResult.Diagnostics.Verify(
// error CS7038: Failed to emit module 'C'.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("C"));
// error CS7038: Failed to emit module 'C': Changing the version of an assembly reference is not allowed during debugging:
// 'Lib, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null' changed version to '1.0.0.2'.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("C",
string.Format(CodeAnalysisResources.ChangingVersionOfAssemblyReferenceIsNotAllowedDuringDebugging,
"Lib, Version=1.0.0.1, Culture=neutral, PublicKeyToken=ce65828c82a341f2", "1.0.0.2")));
}

private void VerifyAssemblyReferences(AggregatedMetadataReader reader, string[] expected)
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Test/Emit/Emit/EmitErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ private static void VerifyEmitDiagnostics(string source2, CSharpCompilation comp

result.Diagnostics.Verify(expectedDiagnostics.Concat(new[]
{
// error CS7038: Failed to emit module 'Test'.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments(compilation2.AssemblyName)
// error CS7038: Failed to emit module 'Test': Unable to determine specific cause of the failure.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments(compilation2.AssemblyName, "Unable to determine specific cause of the failure.")
}).ToArray());
}

Expand Down
Loading