【发布时间】:2018-03-16 13:17:53
【问题描述】:
抱歉,标题太长了!我对 dotnet core 很陌生,所以我怀疑我在这里遇到了依赖问题,但我不太明白为什么。如下:
我已将 .Net 4.5.2 库重建为 .Net Standard 2.0 库。该库依赖于 Newtonsoft.Json 11.0.1。我将整个项目打包为(本地)nuget 包,因为这似乎是使其可用于多个项目的适当方式。这是回购:https://github.com/oliver-wood/realex-hpp-dotnet-standard。
这个想法是在 dotnet core 2.0 web 项目中引用这个包。所以我启动了 Visual Studio 并选择了一个普通的 ASP.Net Core MVC 2.0 应用程序。快速调试表明它启动正常。 https://github.com/oliver-wood/realex-test-dotnetcore
然后我安装了 nuget 包,Web 项目构建没有问题。但是,一旦我开始调试,就会出现运行时错误:
System.TypeLoadException has been thrown
"Could not load type 'System.Runtime.Serialization.SerializationBinder'
from assembly 'netstandard, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'."
at Newtonsoft.Json.JsonSerializer..ctor()
at Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings settings)
at Microsoft.AspNetCore.Mvc.ViewFeatures.CookieTempDataProvider..ctor(IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IOptions`1 options)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass22_0.<RealizeService>b__0(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)
at realex_test_dotnetcore.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in /Users/oliver/Dev/realex-test-dotnetcore/realex-test-dotnetcore/Startup.cs:line 41
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at realex_test_dotnetcore.Program.BuildWebHost(String[] args) in /Users/oliver/Dev/realex-test-dotnetcore/realex-test-dotnetcore/Program.cs:line 21
at realex_test_dotnetcore.Program.Main(String[] args) in /Users/oliver/Dev/realex-test-dotnetcore/realex-test-dotnetcore/Program.cs:line 17
从堆栈往下看,Json.Net 是牵连的,看起来它是通过 Startup.cs 调用 app.UseMvc() 在后台调用的。
看起来很像 Newtonsoft.Json 和内置的 dotnet 核心库之间存在冲突,但我不确定如何缩小和纠正它。任何关于如何解决或解决问题的想法将不胜感激!
在下面的 @will-x 评论后于 3 月 17 日编辑
我已经在 netstandard 1.6 上重建了 nuget 包。这涉及安装更多的软件包来填补 corefx 中的空白,并适当地重写一些代码。 Newtonsoft.Json 仍然是最新版本,11.0.1。
这在我看来并不理想,但可以让我继续发展。我很确定我的客户不会给猴子,但我会;如果可能的话,我更愿意使用所有东西的最新版本,但如果有问题,我想实用主义会胜出。
【问题讨论】:
-
您是否在 .NET Standard 项目中手动创建了 nuspec?看起来你的项目文件中有包信息,但你也有这个 nuspec。
-
你是对的。我最初确实这样做了。好地方!但是,我最终还是让 VS2017 创建了包。我已经删除了该文件并重建了所有内容。很高兴我这样做了,但问题仍然存在:(
-
你在做完这个之后有没有升级包版本?否则,新包将不会被拉取,应用程序将继续使用已下载的旧版本。
-
谢谢@ChrisPratt。是的,我确保增加版本号。没有骰子。
标签: asp.net-core