0
votes

I am facing below issue while migrating .Net Core 2.2 MVC project to 3.1 .

Method not found: 'System.Collections.Generic.IList`1<Microsoft.Extensions.FileProviders.IFileProvider> Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions.get_FileProviders()'.

Any Suggestions are welcome.

Below is the sample Code.

  1. ConfigureServices Method.

    services.Configure<MvcRazorRuntimeCompilationOptions>(options =>
    {
        options.FileProviders.Clear();
        options.FileProviders.Add(new EmbeddedFileProvider(typeof(HomeController).GetType().Assembly));
    });
    services.AddControllersWithViews().AddRazorRuntimeCompilation();
    
  2. Configure Method.

    app.UseRouting();
    
    app.UseEndpoints(endpoints =>
    {
        // Mapping of endpoints goes here:
        endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");         
    });
    
  3. Controller.

    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
    

Let me know If further details are required.

1
can you post your home view?Alex Leo
Can you show your .csproj? It sounds like your rerences aren’t properly updated.poke
@poke I can not do that. As far as I know I have updated all the required references.Vishal P

1 Answers

1
votes

You need the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package and these usings:

using System.Reflection;
using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation;
using Microsoft.Extensions.FileProviders;

You can also have the code something like this for ex:

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.MvcRazorRuntimeCompilationOptions>(options =>
    {
        options.FileProviders.Add(
        new EmbeddedFileProvider(typeof(HomeController).GetTypeInfo().Assembly));
    });
    
    // Requires using System.Reflection;
    var assembly = typeof(HomeController).GetTypeInfo().Assembly;
    services.AddMvc().AddRazorRuntimeCompilation()
                    .AddApplicationPart(assembly)
                    .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
}