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"
添加到我的依賴沒有成功。
有誰知道我必須做什麼才能成功啓動我的項目?
什麼是解決方案的目標框架? 4.0或更高。如果更高,請嘗試設置爲4.0。 – Wheels73
目標是netcoreapp1.0;因爲我使用ASP Core,我無法將其設置爲4.0,4.5等。 – wertzui
您是否嘗試將它作爲從屬程序集添加到config中? –
Wheels73