2017-01-30 28 views
0

时,我有一个ASP.Net核心应用,当我尝试启动它,下面的行抛出一个System.TypeLoadException获取TypeLoadException开始ASP.Net核心应用

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%" ] 
    } 
} 

引用的项目全部NE tstandard1.5

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

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

+0

什么是解决方案的目标框架? 4.0或更高。如果更高,请尝试设置为4.0。 – Wheels73

+0

目标是netcoreapp1.0;因为我使用ASP Core,我无法将其设置为4.0,4.5等。 – wertzui

+0

您是否尝试将它作为从属程序集添加到config中? Wheels73

回答

1

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

线

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

应该是

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

那么这将(从控制台使用“的dotnet运行”以查看错误消息)产生在启动时出现错误。

该错误说明1.1.0的Microsoft.NETCore.App丢失。

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