0

I've been trying to import in a ASP.NET Core MVC view of the already compiled view *.Views.dll between the possible views.

Caution!

I have no intention of adding the *.views.dll file among the resources being compiled but afterwards.

To make things clear, the running program must take the file from a folder and read it by adding the contents of the assembly file to its views

To get more information I'll give you the link of the speech in the qule is connected

In addition I do not want to use the embedded resource because the view remains clear.

link

I tried this

    services.AddMvc().ConfigureApplicationPartManager(apm =>{
            var part = new AssemblyPart(AssemblyLoadContext.Default.LoadFromAssemblyPath("C:\\Users\\gianf\\source\\repos\\ViewTestPlugin2\\plug\\bin\\Debug\\netcoreapp2.1\\plug.Views.dll"));
            apm.ApplicationParts.Add(part);
        });

Resolved!!!

looking at the assembly of the * .views.dll file I noticed this

[assembly: ProvideApplicationPartFactory("Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFactory, Microsoft.AspNetCore.Mvc.Razor")]

so as a result I tried to manually set it like this:

    services.AddMvc().ConfigureApplicationPartManager(apm =>
    {
        var a = new CompiledRazorAssemblyApplicationPartFactory();
        foreach (var b in a.GetApplicationParts(AssemblyLoadContext.Default.LoadFromAssemblyPath("C:\\Users\\gianf\\source\\repos\\ViewTestPlugin2\\plug\\bin\\Debug\\netcoreapp2.1\\plug.Views.dll")))
            apm.ApplicationParts.Add(b);
    });

and so it works, I think AssemblyPart is broken

6
  • Use an EmbeddedFileProvider? Commented Oct 13, 2018 at 18:00
  • no because the views remain clear Commented Oct 13, 2018 at 18:06
  • AssemblyLoadContext.Default.LoadFromAssemblyPath ? But you'd have to do it very early in your application and (iirc) can't do that after the application started, since the IoC is configured and built already at that point Commented Oct 13, 2018 at 19:23
  • @Tseng it's what I use to read the file as an assembly but then as I add the razorpage contained to the mvc service provider? Commented Oct 13, 2018 at 19:26
  • ASP.NET Core should do that on startup, that's why I said you have to do it very early, like in Main method. Also make sure to use `AssemblyLoadContext.Default' as according to this only from there it will be discovered by the DI/IoC system Commented Oct 13, 2018 at 19:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.