Check for empty location in ViewsFeatureProvider

Fixes #5675
This commit is contained in:
Pranav K 2017-01-13 12:07:28 -08:00
parent ce53675b87
commit e749a80b30
2 changed files with 25 additions and 1 deletions

View File

@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
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

View File

@ -90,6 +90,23 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
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<AssemblyPart, Type> _containerLookup;
@ -125,5 +142,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
{
}
}
private class AssemblyWithEmptyLocation : Assembly
{
public override string Location => string.Empty;
public override string FullName => typeof(ViewsFeatureProviderTest).GetTypeInfo().Assembly.FullName;
}
}
}