From 4d969ea696f68de72c86b6ec61e0ddbb86f2224d Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 13 Jan 2017 12:07:28 -0800 Subject: [PATCH] Check for empty location in ViewsFeatureProvider Fixes #5675 --- .../Compilation/ViewsFeatureProvider.cs | 2 +- .../Compilation/ViewsFeatureProviderTest.cs | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/ViewsFeatureProvider.cs b/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/ViewsFeatureProvider.cs index 407b7c8e12..3b75b0606c 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/ViewsFeatureProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/ViewsFeatureProvider.cs @@ -58,7 +58,7 @@ public void PopulateFeature(IEnumerable parts, ViewsFeature fea protected virtual Type GetViewInfoContainerType(AssemblyPart assemblyPart) { #if NETSTANDARD1_6 - if (!assemblyPart.Assembly.IsDynamic && assemblyPart.Assembly.Location != null) + if (!assemblyPart.Assembly.IsDynamic && !string.IsNullOrEmpty(assemblyPart.Assembly.Location)) { var precompiledAssemblyFileName = assemblyPart.Assembly.GetName().Name + PrecompiledViewsAssemblySuffix diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/ViewsFeatureProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/ViewsFeatureProviderTest.cs index 5a41914aac..cbc32c5ecf 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/ViewsFeatureProviderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/ViewsFeatureProviderTest.cs @@ -90,6 +90,23 @@ public void PopulateFeature_ReturnsEmptySequenceIfNoDynamicAssemblyPartHasViewAs Assert.Empty(feature.Views); } + [Fact] + public void PopulateFeature_DoesNotFail_IfAssemblyHasEmptyLocation() + { + // Arrange + var assembly = new AssemblyWithEmptyLocation(); + var applicationPartManager = new ApplicationPartManager(); + applicationPartManager.ApplicationParts.Add(new AssemblyPart(assembly)); + applicationPartManager.FeatureProviders.Add(new ViewsFeatureProvider()); + var feature = new ViewsFeature(); + + // Act + applicationPartManager.PopulateFeature(feature); + + // Assert + Assert.Empty(feature.Views); + } + private class TestableViewsFeatureProvider : ViewsFeatureProvider { private readonly Dictionary _containerLookup; @@ -125,5 +142,12 @@ public ViewInfoContainer2() { } } + + private class AssemblyWithEmptyLocation : Assembly + { + public override string Location => string.Empty; + + public override string FullName => typeof(ViewsFeatureProviderTest).GetTypeInfo().Assembly.FullName; + } } }