I get an internal server error when starting a simple hello world application using .Net core 1.0 on Ubuntu. I am sure that I missed something simple, but I can not understand what it is. It worked until I replaced return Content("Hello, world!"); on return View(); in HomeController and added using System.IO; and .UseContentRoot(Directory.GetCurrentDirectory()) in Program.cs.
I tried adding System and System.X to my dependency list in Startup.cs to no avail.
Program.cs
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(); } } }
project.json
{ "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": {} } }
Startup.cs
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(); } } }
HomeController.cs
using Microsoft.AspNetCore.Mvc; namespace aspnetcoreapp { [Route("/")] [Route("[controller]")] public class HomeController : Controller { public IActionResult Index() { return View(); } } }
dotnet run
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:
Result
An error occurred while compiling the resource required to process this request. Check out the following specific error. details and modify the source code accordingly.
Generated code
The type or namespace name 'System' could not be found (are you missing the using directive or assembly reference?) Using the system; The type or name of the System namespace could not be found (did you specify a usage directive or assembly reference?) Using System.Linq; The type or namespace name "System" could not be found (did you specify a usage directive or assembly reference?) Using System.Collections.Generic; The type or name of the namespace "ViewFeatures" does not exist in the namespace "Microsoft.AspNetCore.Mvc" (do you miss the assembly reference?) Using Microsoft.AspNetCore.Mvc.ViewFeatures; The type or name of the System namespace could not be found (do you miss the using directive or assembly reference?) Using System.Threading.Tasks; It is not possible to define a class or member that uses "dynamic" because the required compiler type 'System.Runtime.CompilerServices.DynamicAttribute' was not found. Are you missing a link? public class _Views_Home_Index_cshtml: Microsoft.AspNetCore.Mvc.Razor.RazorPage The predefined type "System.Boolean" is not defined or is not imported public class _Views_Home_Index_cshtml: Microsoft.AspNetCore.Mvc.Razor.RazorPage is not referenced in the collection "Object type" . You should add a reference to the assembly "System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a '. Public class _Views_Home_Index_cshtml: Microsoft.AspNetCore.Mvc.Razor.RazorPage Type" Object "defined in an assembly that is not You must add a reference to the assembly 'System.Runtime, Version = 4.1.0.0, Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a'. open Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider {get; private recruitment; } The predefined type "System.Object" is not defined or is not imported open Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider {get; private recruitment; } The type or namespace name 'ViewFeatures' does not exist in the namespace "Microsoft.AspNetCore.Mvc" (do you miss the assembly reference?) Open Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider {get; private recruitment; } The predefined type "System.Void" is not defined or the open Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider {get; private recruitment; } The type "Object" defined in the assembly that is not referenced. You must add a reference to the assembly "System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a '. Public Microsoft.AspNetCore.Mvc.IUrlHelper Url {get; private set;} The predefined type" System.Object "is not whether Microsoft.AspNetCore.Mvc.IUrlHelper Url {get; private set;} is defined or not imported; the namespace type or name "IUrlHelper" does not exist in the namespace 'Microsoft.AspNetCore.Mvc' (you are missing the Help build?) is Microsoft public. AspNetCore.Mvc.IUrlHelper Url {get; private set;} The predefined type "System.Void" is not defined or the public Microsoft.AspNetCore.Mvc.IUrl is not imported Helper Url {get; private set;} The type "Object" is defined in the assembly, which is not a link. You must add a link to the assembly 'System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'. Open component Microsoft.AspNetCore.Mvc.IViewComponentHelper {get; private recruitment; } The predefined type "System.Object" is not defined or imported open component Microsoft.AspNetCore.Mvc.IViewComponentHelper {get; private recruitment; } The type or name of the namespace "IViewComponentHelper" does not exist in the namespace "Microsoft.AspNetCore.Mvc" (do you miss the assembly reference?) Open component Microsoft.AspNetCore.Mvc.IViewComponentHelper {get; private recruitment; } The predefined type 'System.Void' is not defined or the imported open component is Microsoft.AspNetCore.Mvc.IViewComponentHelper {get; private recruitment; } The type "Object" is defined in an assembly that is not mentioned. You must add a reference to the assembly 'System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a. publicly available Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json {get; private recruitment; } The predefined type "System.Object" is not defined or the import is public Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json {get; private recruitment; } 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 recruitment; } The predefined type 'System.Void' is not defined or the import is public Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json {get; private recruitment; } The type "Object" is defined in an assembly that is not mentioned. You must add a reference to the assembly 'System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a. open Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get; private recruitment; } The predefined type 'System.Object' is not defined or imported open by Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get; private recruitment; } The name of the type or namespace 'IHtmlHelper <>' does not exist in the namespace "Microsoft.AspNetCore.Mvc.Rendering" (do you miss the assembly reference?) Open Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get; private recruitment; } The type "Object" is defined in an assembly that is not referenced. You must add a reference to the assembly 'System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a. open Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get; private recruitment; } The predefined type 'System.Object' is not defined or imported open by Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get; private recruitment; } It is not possible to define a class or member that uses "dynamic" because the required compiler type 'System.Runtime.CompilerServices.DynamicAttribute' was not found. Are you missing a link? open Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get; private recruitment; } The predefined type 'System.Boolean' is not defined or imported open Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get; private recruitment; } The predefined type 'System.Void' is not defined or imported open by Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get; private recruitment; } The return type of the asynchronization 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 the assembly "System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a '. Public override async Task ExecuteAsync () The predefined type" System.Object "is not defined or the public override async is not imported Task ExecuteAsync () The name or type of the namespace βTaskβ could not be found (do you miss the use of the directive or the assembly reference?) Public override async Task ExecuteAsync () '_Views_Home_Index_cshtml.ExecuteAsync ()': the returned type must be "Task", to match overridden member "RazorPage.ExecuteAsync ()" public override async Task ExecuteAsync () Type "Task" defined It is placed in an assembly that is not referenced. You must add a reference to the assembly "System.Threading.Tasks, Version = 4.0.10.0, Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a '. public override async Task ExecuteAsync () The predefined type "System.Void" is not defined or is not imported public _Views_Home_Index_cshtml () {} The type "Object" is defined in an assembly that is not referenced. You must add a link to the assembly 'System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The attribute type is defined in an assembly that is not referenced. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type "System.Object" is not defined or not imported. . You must add a reference to the assembly "System.Runtime, Version = 4.1.0.0", Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a '. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type "System.Void" is not defined or not 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 the assembly "System.Runtime, Version = 4.1.0.0", Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a '. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type 'System.Object' is not defined or not imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The attribute type is defined in an assembly that is not referenced . You must add a reference to the assembly "System.Runtime, Version = 4.1.0.0", Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a '. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type "System.Void" is not defined or not 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 the assembly "System.Runtime, Version = 4.1.0.0", Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a '. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The attribute type is defined in an assembly that is not referenced. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type "System.Object" is not defined or not imported. . You must add a reference to the assembly "System.Runtime, Version = 4.1.0.0", Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a '. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type "System.Void" is not defined or not 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 the assembly "System.Runtime, Version = 4.1.0.0", Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a '. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The attribute type is defined in an assembly that is not referenced. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type "System.Object" is not defined or not imported. . You must add a reference to the assembly "System.Runtime, Version = 4.1.0.0", Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a '. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type "System.Void" is not defined or not 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 the assembly "System.Runtime, Version = 4.1.0.0", Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a '. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The attribute type is defined in an assembly that is not referenced. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type "System.Object" is not defined or not imported. . You must add a reference to the assembly "System.Runtime, Version = 4.1.0.0", Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a '. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type "System.Void" is not defined or is not imported [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] The predefined type "System.Void" is not defined or not imported public _Views_Home_Index_cshtml () The predefined type 'System.Int32' is not defined or imported BeginContext (0, 181, true); The predefined type "System.Int32" is not defined or imported BeginContext (0, 181, true); The predefined type "System.Boolean" is not defined or not imported BeginContext (0, 181, true); The type "Object" is defined in an assembly that is not referenced. You must add a reference to the assembly 'System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a. BeginContext (0, 181, true); The predefined type "System.Object" is not defined or not imported BeginContext (0, 181, true); The predefined type "System.Void" is not defined or not imported BeginContext (0, 181, true); The predefined type "System.String" is not defined or imported WriteLiteral ("\ n \ n \ n \ n \ n \ n aspnetcoreapp \ n
\ n \ n \ n
Hello world!
\ n
\ n \ n "); The type 'Object' is defined in an assembly that is not mentioned. You must add a reference to the 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 "); the predefined type 'System.Object' is not defined or imported WriteLiteral (" \ n \ n \ n \ n \ n \ n aspnetcoreapp \ n
\ n \ n \ nHello World!
\ P
\ n \ n "); the predefined type 'System.Void' is not defined or the import 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 mentioned. You must add a reference to the assembly 'System.Runtime, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a. EndContext (); Predefined type "System.Object" is not defined or not imported EndContext (); The predefined type "System.Void" is not defined or not imported EndContext (); '_Views_Home_Index_cshtml.ExecuteAsync ()': not all code paths return public override async Value ExecuteAsync ( )