I am getting an internal server error while running a simple "hello world" application using .Net core 1.0 on Ubuntu. I'm sure that I'm missing something simple, but can't figure out what it is. It was working until I replaced return Content("Hello, world!");
with return View();
in HomeController, and added using System.IO;
and .UseContentRoot(Directory.GetCurrentDirectory())
to Program.cs.
I have tried adding System
and System.X
to my list of dependencies in Startup.cs to no avail.
using Microsoft.AspNetCore.Hosting;
using System.IO;
namespace aspnetcoreapp
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" }
},
"frameworks": {
"netcoreapp1.0": {}
}
}
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace aspnetcoreapp
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseDeveloperExceptionPage();
app.UseStaticFiles();
app.UseMvc();
}
}
}
using Microsoft.AspNetCore.Mvc;
namespace aspnetcoreapp
{
[Route("/")]
[Route("[controller]")]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
Project aspnetcoreapp (.NETCoreApp,Version=v1.0) will be compiled because inputs were modified
Compiling aspnetcoreapp for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:01.0784778
Hosting environment: Production
Content root path: /home/cvandal/code/aspnetcoreapp
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
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
The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) using System; The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) using System.Linq; The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) using System.Collections.Generic; The type or namespace name 'ViewFeatures' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) using Microsoft.AspNetCore.Mvc.ViewFeatures; The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) using System.Threading.Tasks; Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference? public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage Predefined type 'System.Boolean' is not defined or imported public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. public Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } Predefined type 'System.Object' is not defined or imported public Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } The type or namespace name 'ViewFeatures' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) public Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } Predefined type 'System.Void' is not defined or imported public Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. public Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } Predefined type 'System.Object' is not defined or imported public Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } The type or namespace name 'IUrlHelper' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) public Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } Predefined type 'System.Void' is not defined or imported public Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. public Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } Predefined type 'System.Object' is not defined or imported public Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } The type or namespace name 'IViewComponentHelper' does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (are you missing an assembly reference?) public Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } Predefined type 'System.Void' is not defined or imported public Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. public Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } Predefined type 'System.Object' is not defined or imported public Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } The type or namespace name 'IJsonHelper' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.Rendering' (are you missing an assembly reference?) public Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } Predefined type 'System.Void' is not defined or imported public Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } Predefined type 'System.Object' is not defined or imported public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } The type or namespace name 'IHtmlHelper<>' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.Rendering' (are you missing an assembly reference?) public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } Predefined type 'System.Object' is not defined or imported public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference? public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } Predefined type 'System.Boolean' is not defined or imported public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } Predefined type 'System.Void' is not defined or imported public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } The return type of an async method must be void, Task or Task public override async Task ExecuteAsync() The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. public override async Task ExecuteAsync() Predefined type 'System.Object' is not defined or imported public override async Task ExecuteAsync() The type or namespace name 'Task' could not be found (are you missing a using directive or an assembly reference?) public override async Task ExecuteAsync() '_Views_Home_Index_cshtml.ExecuteAsync()': return type must be 'Task' to match overridden member 'RazorPage.ExecuteAsync()' public override async Task ExecuteAsync() The type 'Task' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Threading.Tasks, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. public override async Task ExecuteAsync() Predefined type 'System.Void' is not defined or imported public _Views_Home_Index_cshtml() { } The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Object' is not defined or imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Void' is not defined or imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Object' is not defined or imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Void' is not defined or imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Object' is not defined or imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Void' is not defined or imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Object' is not defined or imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Void' is not defined or imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Object' is not defined or imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Void' is not defined or imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] Predefined type 'System.Void' is not defined or imported public _Views_Home_Index_cshtml() Predefined type 'System.Int32' is not defined or imported BeginContext(0, 181, true); Predefined type 'System.Int32' is not defined or imported BeginContext(0, 181, true); Predefined type 'System.Boolean' is not defined or imported BeginContext(0, 181, true); The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. BeginContext(0, 181, true); Predefined type 'System.Object' is not defined or imported BeginContext(0, 181, true); Predefined type 'System.Void' is not defined or imported BeginContext(0, 181, true); Predefined type 'System.String' is not defined or imported WriteLiteral("\n\n\n \n \n\n aspnetcoreapp\n
\n \n \nHello, world!
\n
\n\n"); The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. WriteLiteral("\n\n\n \n \n\n aspnetcoreapp\n
\n \n \nHello, world!
\n
\n\n"); Predefined type 'System.Object' is not defined or imported WriteLiteral("\n\n\n \n \n\n aspnetcoreapp\n
\n \n \nHello, world!
\n
\n\n"); Predefined type 'System.Void' is not defined or imported WriteLiteral("\n\n\n \n \n\n aspnetcoreapp\n
\n \n \nHello, world!
\n
\n\n"); The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. EndContext(); Predefined type 'System.Object' is not defined or imported EndContext(); Predefined type 'System.Void' is not defined or imported EndContext(); '_Views_Home_Index_cshtml.ExecuteAsync()': not all code paths return a value public override async Task ExecuteAsync()
Under the buildOptions
node in project.json
, add an entry called "preserveCompilationContext": true
and this should fix the above error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With