Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

ViewsFeatureProvider and dynamic assemblies #5487

Closed
mdschweda opened this issue Nov 2, 2016 · 2 comments
Closed

ViewsFeatureProvider and dynamic assemblies #5487

mdschweda opened this issue Nov 2, 2016 · 2 comments
Assignees
Milestone

Comments

@mdschweda
Copy link
Contributor

mdschweda commented Nov 2, 2016

protected virtual Type GetViewInfoContainerType(AssemblyPart assemblyPart)
{
    if (assemblyPart.Assembly.Location != null)
    {
        // ...
    }
    // ...
}

in ViewFeaturesProvider fails when adding dynamic assemblies via IMvcBuilder.AddApplicationPart (System.Reflection.Emit.AssemblyBuilder.Location throws NotSupportedException). Here is a stack trace:

System.NotSupportedException: The invoked member is not supported in a dynamic assembly.
   at System.Reflection.Emit.InternalAssemblyBuilder.get_Location()
   at Microsoft.AspNetCore.Mvc.Razor.Compilation.ViewsFeatureProvider.GetViewInfoContainerType(AssemblyPart assemblyPart)
   at Microsoft.AspNetCore.Mvc.Razor.Compilation.ViewsFeatureProvider.PopulateFeature(IEnumerable`1 parts, ViewsFeature feature)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
   at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultCompilerCacheProvider..ctor(ApplicationPartManager applicationPartManager, IRazorViewEngineFileProviderAccessor fileProviderAccessor)

Would there be any major implications when checking if assemblyPart.Assembly.IsDynamic before trying to retrieve its location? Am I missing something when working with dynamic assemblies in projects with controllers returning views?

@pranavkm
Copy link
Contributor

pranavkm commented Nov 2, 2016

Would there be any major implications when checking if assemblyPart.Assembly.IsDynamic before trying to retrieve its location?

That sounds fine. I recall trying out loading a Roslyn generated assembly and it didn't throw when Location was accessed. Would you like to send a pull request for this?

@mdschweda
Copy link
Contributor Author

Sure

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants