在Ubuntu 16.04上运行简单的.Net Core MVC应用程序时出现内部服务器错误 [英] Internal Server Error while running a simple .Net Core MVC application on Ubuntu 16.04

查看:105
本文介绍了在Ubuntu 16.04上运行简单的.Net Core MVC应用程序时出现内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ubuntu上使用.Net core 1.0运行简单的"hello world"应用程序时,出现内部服务器错误.我确定我缺少一些简单的东西,但无法弄清楚它是什么.直到我在HomeController中将return Content("Hello, world!");替换为return View();,并将using System.IO;.UseContentRoot(Directory.GetCurrentDirectory())添加到Program.cs为止.

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.

我尝试将SystemSystem.X添加到我在Startup.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();
        }
    }
}

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运行

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.

生成的代码

找不到类型或名称空间名称系统"(您是 缺少using指令或程序集引用?) 使用系统;找不到类型或名称空间名称系统"(您是否缺少using指令或程序集引用?) 使用System.Linq;找不到类型或名称空间名称系统"(您是否缺少using指令或程序集引用?) 使用System.Collections.Generic;类型或名称空间名称"ViewFeatures"在名称空间中不存在 'Microsoft.AspNetCore.Mvc'(您是否缺少程序集引用?) 使用Microsoft.AspNetCore.Mvc.ViewFeatures;找不到类型或名称空间名称系统"(您是否缺少using指令或 组装参考?) 使用System.Threading.Tasks;无法定义利用动态"的类或成员,因为编译器需要使用类型 找不到"System.Runtime.CompilerServices.DynamicAttribute". 您是否缺少参考? 公共类_Views_Home_Index_cshtml:Microsoft.AspNetCore.Mvc.Razor.RazorPage预定义类型 未定义或导入"System.Boolean" 公共类_Views_Home_Index_cshtml:Microsoft.AspNetCore.Mvc.Razor.RazorPage类型对象"为 在未引用的程序集中定义.您必须添加一个 引用程序集"System.Runtime,版本= 4.1.0.0, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. 公共类_Views_Home_Index_cshtml:Microsoft.AspNetCore.Mvc.Razor.RazorPage类型对象"为 在未引用的程序集中定义.您必须添加一个 引用程序集"System.Runtime,版本= 4.1.0.0, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. 公共Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider {get;私人套装; }预定义类型 未定义或导入"System.Object" 公共Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider {get;私人套装;类型或名称空间 名称'ViewFeatures'在名称空间中不存在 'Microsoft.AspNetCore.Mvc'(您是否缺少程序集引用?) 公共Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider {get;私人套装; }预定义类型 未定义或导入"System.Void" 公共Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider {get;私人套装; }对象"类型为 在未引用的程序集中定义.您必须添加一个 引用程序集"System.Runtime,版本= 4.1.0.0, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. 公共Microsoft.AspNetCore.Mvc.IUrlHelper网址{get;私人套装;未定义或导入预定义类型"System.Object" 公共Microsoft.AspNetCore.Mvc.IUrlHelper网址{get;私人套装; }类型或名称空间名称"IUrlHelper"在 命名空间"Microsoft.AspNetCore.Mvc"(您是否缺少程序集 参考?) 公共Microsoft.AspNetCore.Mvc.IUrlHelper网址{get;私人套装;未定义或导入"System.Void"预定义类型 公共Microsoft.AspNetCore.Mvc.IUrlHelper网址{get;私人套装; }对象"类型是在不是 参考.您必须添加对程序集'System.Runtime的引用, 版本= 4.1.0.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. 公共Microsoft.AspNetCore.Mvc.IViewComponentHelper组件{私人套装;未定义预定义类型"System.Object" 或进口 公共Microsoft.AspNetCore.Mvc.IViewComponentHelper组件{私人套装; }类型或名称空间名称 名称空间中不存在"IViewComponentHelper" 'Microsoft.AspNetCore.Mvc'(您是否缺少程序集引用?) 公共Microsoft.AspNetCore.Mvc.IViewComponentHelper组件{私人套装; }预定义类型'System.Void'未定义或 进口的 公共Microsoft.AspNetCore.Mvc.IViewComponentHelper组件{私人套装; }'Object'类型是在程序集中定义的,该程序集 未引用.您必须添加对程序集的引用 'System.Runtime,版本= 4.1.0.0,区域性=中性, PublicKeyToken = b03f5f7f11d50a3a'. 公共Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json {get;私人套装; }未定义预定义类型'System.Object'或 进口的 公共Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json {get;私人套装;类型或名称空间名称"IJsonHelper"不 存在于命名空间"Microsoft.AspNetCore.Mvc.Rendering"中(您是 缺少程序集引用?) 公共Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json {get;私人套装; }预定义类型'System.Void'未定义或 进口的 公共Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json {get;私人套装; }'Object'类型是在程序集中定义的,该程序集 未引用.您必须添加对程序集的引用 'System.Runtime,版本= 4.1.0.0,区域性=中性, PublicKeyToken = b03f5f7f11d50a3a'. 公共Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get;私人套装; }预定义类型'System.Object'不是 定义或导入 公共Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get;私人套装; }类型或名称空间名称'IHtmlHelper<>' 名称空间'Microsoft.AspNetCore.Mvc.Rendering'中不存在 (您是否缺少程序集参考?) 公共Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get;私人套装; }'Object'类型是在程序集中定义的 没有引用.您必须添加对程序集的引用 'System.Runtime,版本= 4.1.0.0,区域性=中性, PublicKeyToken = b03f5f7f11d50a3a'. 公共Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get;私人套装; }预定义类型'System.Object'不是 定义或导入 公共Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get;私人套装;不能定义一个类或成员 利用动态",因为编译器需要类型 找不到"System.Runtime.CompilerServices.DynamicAttribute". 您是否缺少参考? 公共Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get;私人套装; }预定义类型'System.Boolean'不是 定义或导入 公共Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get;私人套装; }预定义类型'System.Void'不是 定义或导入 公共Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html {get;私人套装;异步方法的返回类型必须为 无效,任务或任务 公共重写async任务ExecuteAsync()类型'Object'是在未引用的程序集中定义的.您必须添加一个 引用程序集"System.Runtime,版本= 4.1.0.0, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. 公共重写async任务ExecuteAsync()未定义或未导入"System.Object"预定义类型 公共重写异步任务ExecuteAsync()找不到类型或名称空间名称任务"(您是否缺少使用 指令还是汇编参考?) 公共重写异步任务ExecuteAsync()'_Views_Home_Index_cshtml.ExecuteAsync()':返回类型必须为'Task' 匹配重写的成员'RazorPage.ExecuteAsync()' 公共重写async任务ExecuteAsync()在未引用的程序集中定义了任务"类型.您必须添加一个 引用程序集'System.Threading.Tasks,Version = 4.0.10.0, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. 公共重写异步任务ExecuteAsync()未定义或未导入"System.Void"预定义类型 公共_Views_Home_Index_cshtml() { }对象"类型是在未引用的程序集中定义的.您必须添加对程序集'System.Runtime的引用, 版本= 4.1.0.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Object"预定义类型 [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]类型'Attribute'是在未引用的程序集中定义的. 您必须添加对程序集'System.Runtime,Version = 4.1.0.0的引用, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Void"预定义类型 [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]类型对象"是在未引用的程序集中定义的. 您必须添加对程序集'System.Runtime,Version = 4.1.0.0的引用, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Object"预定义类型 [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]类型'Attribute'是在未引用的程序集中定义的. 您必须添加对程序集'System.Runtime,Version = 4.1.0.0的引用, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Void"预定义类型 [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]类型对象"是在未引用的程序集中定义的. 您必须添加对程序集'System.Runtime,Version = 4.1.0.0的引用, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Object"预定义类型 [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]类型'Attribute'是在未引用的程序集中定义的. 您必须添加对程序集'System.Runtime,Version = 4.1.0.0的引用, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Void"预定义类型 [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]类型对象"是在未引用的程序集中定义的. 您必须添加对程序集'System.Runtime,Version = 4.1.0.0的引用, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Object"预定义类型 [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]类型'Attribute'是在未引用的程序集中定义的. 您必须添加对程序集'System.Runtime,Version = 4.1.0.0的引用, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Void"预定义类型 [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]类型对象"是在未引用的程序集中定义的. 您必须添加对程序集'System.Runtime,Version = 4.1.0.0的引用, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Object"预定义类型 [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]类型'Attribute'是在未引用的程序集中定义的. 您必须添加对程序集'System.Runtime,Version = 4.1.0.0的引用, 文化=中性,PublicKeyToken = b03f5f7f11d50a3a'. [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Void"预定义类型 [Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]未定义或导入了"System.Void"预定义类型 public _Views_Home_Index_cshtml()预定义类型'System.Int32'未定义或导入 BeginContext(0,181,true);未定义或导入预定义类型'System.Int32' BeginContext(0,181,true);未定义或导入预定义类型"System.Boolean" BeginContext(0,181,true);类型对象"是在未引用的程序集中定义的.您必须添加对 程序集'System.Runtime,Version = 4.1.0.0,Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'. BeginContext(0,181,true);未定义或导入预定义类型"System.Object" BeginContext(0,181,true);未定义或导入预定义类型"System.Void" BeginContext(0,181,true);未定义或导入预定义类型'System.String' WriteLiteral("\ n \ n \ n \ n \ n \ n aspnetcoreapp \ n
\ n \ n \ n

世界,您好!

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 \n

Hello, world!

世界,您好!

世界,您好!

世界,您好!

推荐答案

project.jsonbuildOptions节点下,添加一个名为"preserveCompilationContext": true的条目,这将解决上述错误.

Under the buildOptions node in project.json, add an entry called "preserveCompilationContext": true and this should fix the above error.

这篇关于在Ubuntu 16.04上运行简单的.Net Core MVC应用程序时出现内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆