_ViewImports.cshtml not being processed
I have been working on a site in which the _ViewImports.cshtml file has seemingly stopped working. When I go to a page within the site, it can't resolve anything that is set up with@using in _ViewImports.
When the @using is added to the main .cshtml file, everything works as expected.
To troubleshoot this issue, I updated Visual Studio to Update 3 and updated .Net Core to 2.01. Neither of these updates changed anything. I started writing the site over with just the bare minimum needed to run the /Home/Index page and still get the same results. Other projects I've been working on have similar issues, but appear to be isolated to specific pages within those apps where in this app it affects all pages.
I am running Windows 7 with all current updates and Visual Studio Professional 2015 Version 14.0.25425.01 Update 3. I am using IIS Express to debug the application.
Can you upload a sample to a github repository?
I'll try to do that over the weekend. I threw together a quick-and-dirty and everything worked as expected, so it very well may be something to do with one of the modules that I'm using (I'm developing a framework for rapid web development) so I'll need to pin that down a little harder before continuing.
After some deep digging, I've determined that this is some quirky interaction between Autofac v4.0.0-rc2-240 and .Net Core 2.00 and up. I don't know enough about Autofac to know exactly what's going on. For now I'm just going to remove it. When I get a chance maybe I'll get with the Autofac author and see what we can come up with.
After moving on to another issue this morning, I found that Autofac is not the issue. I'm trying to keep common files in separate assemblies and when registering these assemblies as embedded file providers, it is causing problems with anything being resolved. I've uploaded a project I started with that can be used to see the issue. As-is, the app at https://github.com/82dsoldier/ViewImportsSample will run properly. If you uncomment the following lines in Startup.cs, it will break:
services.Configure<RazorViewEngineOptions>(options => {
options.FileProviders.Add(new EmbeddedFileProvider(typeof(ControllerCore).GetTypeInfo().Assembly, "QuickFrame.Mvc"));
});
IOptions<RazorViewEngineOptions> razorViewEngineOptions =
app.ApplicationServices.GetService<IOptions<RazorViewEngineOptions>>();
razorViewEngineOptions.Value.FileProviders.Add(new EmbeddedFileProvider(
typeof(ControllerCore).GetTypeInfo().Assembly,
"QuickFrame.Mvc"));
I sent a PR to your repo here: https://github.com/82dsoldier/ViewImportsSample/pull/1. There might be some oddities with the ordering of Configure<> that might have caused some of Mvc's default option configuration from not kicking in. But reordering it seems to fix it.
Closing this for now. Please feel free to reopen this if you still see issues once you've incorporated the changes from my PR.