启动ASP.Net Core App时获取TypeLoadException

时间:2017-01-30 08:41:19

标签: c# asp.net asp.net-core asp.net-core-mvc .net-core

我有一个ASP.Net核心应用程序,当我尝试启动它时,以下行抛出System.TypeLoadException

    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

        if (env.IsEnvironment("Development"))
        {
            // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
            builder.AddApplicationInsightsSettings(developerMode: true);
        }

        builder.AddEnvironmentVariables();
        Configuration = builder.Build(); // <-- exception is thrown here
    }

例外情况为:

Could not load type 'System.Runtime.Serialization.ISerializable' from assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

这就是我的project.json的样子:

{
  "dependencies": {
    "adremes.Common": "1.1.0",
    "adremes.Data": "1.1.2",
    "AutoMapper": "5.2.0",
    "Microsoft.AspNetCore.Hosting.Abstractions": "1.1.0",
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.SignalR.Server": "0.2.0-preview2-22683",
    "Microsoft.AspNetCore.WebSockets": "1.1.0-preview1-23121",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.NETCore.App": "1.1.0",
    "AutoMapper.Collection": "2.1.2",
    "Microsoft.AspNetCore.Identity": "1.1.0",
    "DocumentFormat.OpenXml": "2.7.0-vnext0061",
    "AspNet.Security.OpenIdConnect.Server": "1.0.0-beta7-final",
    "AspNet.Security.OAuth.Validation": "1.0.0-alpha3-final",
    "Microsoft.ApplicationInsights.AspNetCore": "2.0.0",
    "Microsoft.AspNetCore.Mvc": "1.1.1"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview4-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "adremes.Exchange.Common": {
          "target": "project"
        },
        "adremes.Exchange.Data": {
          "target": "project"
        },
        "adremes.Exchange.Services": {
          "target": "project"
        }
      },
      "imports": [
        "dnxcore50"
      ]
    }
  },
  "runtimes": {
    "win10-x64": {}
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "allowUnsafe": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

引用的项目都是netstandard1.5

我尝试将"System.Runtime.Serialization.Primitives": "4.3.0"添加到我的依赖项中但没有成功。

有谁知道我必须做些什么来成功启动我的项目?

1 个答案:

答案 0 :(得分:1)

问题出在project.json的依赖项部分。

该行

"Microsoft.NETCore.App": "1.1.0",

应该是

"Microsoft.NETCore.App": {
  "type": "platform",
  "version": "1.1.0"
},

然后这会在启动时生成错误(从控制台使用“dotnet run”以查看错误消息)。

该错误表示缺少1.1.0版的Microsoft.NETCore.App。

https://www.microsoft.com/net/download/core#/current安装,然后修复问题。

相关问题