From c12a4795caab5ef623386d179abb2f20351198f2 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 11 Aug 2014 10:25:12 -0700 Subject: [PATCH] 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. --- .../Compilation/CompilationResult.cs | 28 ++----------------- .../Compilation/RoslynCompilationService.cs | 7 +---- .../Razor/RazorCompilationService.cs | 2 +- .../Compilation/CompilationResultTest.cs | 3 +- 4 files changed, 5 insertions(+), 35 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilationResult.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilationResult.cs index 7fbcac81b2..7c520db3ad 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilationResult.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilationResult.cs @@ -39,18 +39,6 @@ namespace Microsoft.AspNet.Mvc.Razor /// public IEnumerable Messages { get; private set; } - /// - /// Gets additional information from compilation. - /// - /// - /// In the event of a compilation failure, values from this dictionary are copied to the - /// property of the thrown. - /// - public IDictionary AdditionalInfo - { - get; private set; - } - /// /// Gets the generated C# content that was compiled. /// @@ -81,19 +69,16 @@ namespace Microsoft.AspNet.Mvc.Razor /// The for the Razor file that was compiled. /// The generated C# content to be compiled. /// The sequence of failure messages encountered during compilation. - /// Additional info about the compilation. /// A CompilationResult instance representing a failure. public static CompilationResult Failed([NotNull] IFileInfo file, [NotNull] string compilationContent, - [NotNull] IEnumerable messages, - IDictionary additionalInfo) + [NotNull] IEnumerable messages) { return new CompilationResult { File = file, CompiledContent = compilationContent, Messages = messages, - AdditionalInfo = additionalInfo }; } @@ -113,16 +98,7 @@ namespace Microsoft.AspNet.Mvc.Razor private CompilationFailedException CreateCompilationFailedException() { var fileContent = ReadContent(File); - var exception = new CompilationFailedException(FilePath, fileContent, CompiledContent, Messages); - if (AdditionalInfo != null) - { - foreach (var item in AdditionalInfo) - { - exception.Data.Add(item.Key, item.Value); - } - } - - return exception; + return new CompilationFailedException(FilePath, fileContent, CompiledContent, Messages); } private static string ReadContent(IFileInfo file) diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs index e176f9afd3..50d134bc8b 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs @@ -22,7 +22,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation /// public class RoslynCompilationService : ICompilationService { - public static readonly string CompilationResultDiagnosticsKey = "Diagnostics"; private static readonly ConcurrentDictionary _metadataFileCache = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); @@ -85,11 +84,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation .Select(d => GetCompilationMessage(formatter, d)) .ToList(); - var additionalInfo = new Dictionary(StringComparer.OrdinalIgnoreCase) - { - { CompilationResultDiagnosticsKey, result.Diagnostics } - }; - return CompilationResult.Failed(fileInfo, compilationContent, messages, additionalInfo); + return CompilationResult.Failed(fileInfo, compilationContent, messages); } Assembly assembly; diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs index 20945a83e8..9775e34e1e 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Mvc.Razor if (!results.Success) { 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); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilationResultTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilationResultTest.cs index 94a75ca5be..675a3dfec5 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilationResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilationResultTest.cs @@ -38,8 +38,7 @@ world"; }; var result = CompilationResult.Failed(fileInfo.Object, "

hello world

", - messages, - additionalInfo); + messages); // Act and Assert var ex = Assert.Throws(() => result.CompiledType);