'View throws "The type or namespace name 'Microsoft' could not be found in the global namespace" with Kestrel running from .NET 4.6.1 Service
I'm about to integrate the ASP.NET Core Webserver into a .NET 4.6.1 project by adding the NuGet packages Microsoft.AspNetCore.* and running the following code at service start:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
static Action<IServiceCollection> _configureServices = (services) => {
services.AddMvc();
services.AddRouting();
};
static Action<IApplicationBuilder> _configure = app => {
app.UseDeveloperExceptionPage();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "app",
template: "app",
defaults: new { controller = "Home", action = "App" });
});
app.Run((ctx) => ctx.Response.WriteAsync("Page not found."));
};
protected void StartKestrel()
{
var host = new WebHostBuilder()
.UseKestrel()
.UseUrls("http://localhost:5000/;https://localhost:5001")
.ConfigureServices(_configureServices)
.Configure(_configure)
.Build();
host.Run();
}
I've managed to run everything fine, the routes and controllers are working perfectly. I'm just not able to return Views from Controllers, it always brings up the error page where it cannot locate the .NET Dlls (See below.)
Am I missing something? Do I need to add a web.config somewhere or missing a build step?
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
Generated Code
>One or more compilation references may be missing. If you're seeing this in a published application, set 'CopyRefAssembliesToPublishDirectory' to true in your project file to ensure files in the refs directory are published.
>
>> The type or namespace name 'Microsoft' could not be found in the global namespace (are you missing an assembly reference?)
>>>[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore._Views_Home_Index), @"mvc.1.0.view", @"/Views/Home/Index.cshtml")]
>>
>> The type or namespace name 'Microsoft' could not be found in the global namespace (are you missing an assembly reference?)
>>>[assembly:global::Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorViewAttribute(@"/Views/Home/Index.cshtml", typeof(AspNetCore._Views_Home_Index))]
>>
>>Predefined type 'System.Type' is not defined or imported
>>>[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore._Views_Home_Index), @"mvc.1.0.view", @"/Views/Home/Index.cshtml")]
>>[...]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
