Removing AdditionalInfo from CompilationResult since we can't always pass
it into exception thrown All values in Exception.Data need to be serializable which is not true for the diagnostics. Removing this property since we can't pass it through.
This commit is contained in:
parent
5e010597cd
commit
c12a4795ca
|
|
@ -39,18 +39,6 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<CompilationMessage> Messages { get; private set; }
|
public IEnumerable<CompilationMessage> Messages { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets additional information from compilation.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// In the event of a compilation failure, values from this dictionary are copied to the
|
|
||||||
/// <see cref="Exception.Data"/> property of the <see cref="Exception"/> thrown.
|
|
||||||
/// </remarks>
|
|
||||||
public IDictionary<string, object> AdditionalInfo
|
|
||||||
{
|
|
||||||
get; private set;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the generated C# content that was compiled.
|
/// Gets the generated C# content that was compiled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -81,19 +69,16 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
/// <param name="fileInfo">The <see cref="IFileInfo"/> for the Razor file that was compiled.</param>
|
/// <param name="fileInfo">The <see cref="IFileInfo"/> for the Razor file that was compiled.</param>
|
||||||
/// <param name="compilationContent">The generated C# content to be compiled.</param>
|
/// <param name="compilationContent">The generated C# content to be compiled.</param>
|
||||||
/// <param name="messages">The sequence of failure messages encountered during compilation.</param>
|
/// <param name="messages">The sequence of failure messages encountered during compilation.</param>
|
||||||
/// <param name="additionalInfo">Additional info about the compilation.</param>
|
|
||||||
/// <returns>A CompilationResult instance representing a failure.</returns>
|
/// <returns>A CompilationResult instance representing a failure.</returns>
|
||||||
public static CompilationResult Failed([NotNull] IFileInfo file,
|
public static CompilationResult Failed([NotNull] IFileInfo file,
|
||||||
[NotNull] string compilationContent,
|
[NotNull] string compilationContent,
|
||||||
[NotNull] IEnumerable<CompilationMessage> messages,
|
[NotNull] IEnumerable<CompilationMessage> messages)
|
||||||
IDictionary<string, object> additionalInfo)
|
|
||||||
{
|
{
|
||||||
return new CompilationResult
|
return new CompilationResult
|
||||||
{
|
{
|
||||||
File = file,
|
File = file,
|
||||||
CompiledContent = compilationContent,
|
CompiledContent = compilationContent,
|
||||||
Messages = messages,
|
Messages = messages,
|
||||||
AdditionalInfo = additionalInfo
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,16 +98,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
private CompilationFailedException CreateCompilationFailedException()
|
private CompilationFailedException CreateCompilationFailedException()
|
||||||
{
|
{
|
||||||
var fileContent = ReadContent(File);
|
var fileContent = ReadContent(File);
|
||||||
var exception = new CompilationFailedException(FilePath, fileContent, CompiledContent, Messages);
|
return new CompilationFailedException(FilePath, fileContent, CompiledContent, Messages);
|
||||||
if (AdditionalInfo != null)
|
|
||||||
{
|
|
||||||
foreach (var item in AdditionalInfo)
|
|
||||||
{
|
|
||||||
exception.Data.Add(item.Key, item.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return exception;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ReadContent(IFileInfo file)
|
private static string ReadContent(IFileInfo file)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RoslynCompilationService : ICompilationService
|
public class RoslynCompilationService : ICompilationService
|
||||||
{
|
{
|
||||||
public static readonly string CompilationResultDiagnosticsKey = "Diagnostics";
|
|
||||||
private static readonly ConcurrentDictionary<string, MetadataReference> _metadataFileCache =
|
private static readonly ConcurrentDictionary<string, MetadataReference> _metadataFileCache =
|
||||||
new ConcurrentDictionary<string, MetadataReference>(StringComparer.OrdinalIgnoreCase);
|
new ConcurrentDictionary<string, MetadataReference>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
|
@ -85,11 +84,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
.Select(d => GetCompilationMessage(formatter, d))
|
.Select(d => GetCompilationMessage(formatter, d))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var additionalInfo = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
|
return CompilationResult.Failed(fileInfo, compilationContent, messages);
|
||||||
{
|
|
||||||
{ CompilationResultDiagnosticsKey, result.Diagnostics }
|
|
||||||
};
|
|
||||||
return CompilationResult.Failed(fileInfo, compilationContent, messages, additionalInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Assembly assembly;
|
Assembly assembly;
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
if (!results.Success)
|
if (!results.Success)
|
||||||
{
|
{
|
||||||
var messages = results.ParserErrors.Select(e => new CompilationMessage(e.Message));
|
var messages = results.ParserErrors.Select(e => new CompilationMessage(e.Message));
|
||||||
return CompilationResult.Failed(file, results.GeneratedCode, messages, additionalInfo: null);
|
return CompilationResult.Failed(file, results.GeneratedCode, messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _baseCompilationService.Compile(file, results.GeneratedCode);
|
return _baseCompilationService.Compile(file, results.GeneratedCode);
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,7 @@ world";
|
||||||
};
|
};
|
||||||
var result = CompilationResult.Failed(fileInfo.Object,
|
var result = CompilationResult.Failed(fileInfo.Object,
|
||||||
"<h1>hello world</h1>",
|
"<h1>hello world</h1>",
|
||||||
messages,
|
messages);
|
||||||
additionalInfo);
|
|
||||||
|
|
||||||
// Act and Assert
|
// Act and Assert
|
||||||
var ex = Assert.Throws<CompilationFailedException>(() => result.CompiledType);
|
var ex = Assert.Throws<CompilationFailedException>(() => result.CompiledType);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue