project.json中是这么写的:
{ "dependencies": { "Microsoft.AspNet.Diagnostics": "1.0.0-beta2", "Microsoft.AspNet.Hosting": "1.0.0-beta2", "Microsoft.AspNet.Server.WebListener": "1.0.0-beta2", "Microsoft.AspNet.StaticFiles": "1.0.0-beta2", "Microsoft.Framework.CodeGeneration": "1.0.0-beta2", "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta2", "Microsoft.AspNet.Mvc": "6.0.0-*" }, "commands": { "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:8001", "gen": "Microsoft.Framework.CodeGeneration" }, "frameworks": { "aspnet50": {} } }
运行k web,出现如下的错误提示:
Missing method Microsoft.Framework.DependencyInjection.ServiceCollectionExtensions::AddContextAccessor(IServiceCollection,IConfiguration) in assembly .kpm/packages/Microsoft.Framework.DependencyInjection/1.0.0-beta3-10747/lib/aspnet50/Microsoft.Framework.DependencyInjection.dll, referenced in assembly .kpm/packages/Microsoft.AspNet.Hosting/1.0.0-beta2/lib/aspnet50/Microsoft.AspNet.Hosting.dll System.MissingMethodException: Method not found: 'Microsoft.Framework.DependencyInjection.ServiceCollectionExtensions.AddContextAccessor'. at Microsoft.AspNet.Hosting.HostingServices.Create (IServiceProvider fallbackServices, IConfiguration configuration) [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Hosting.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
请问如何解决这个问题?
在project.json的dependencies中添加
"Microsoft.Framework.DependencyInjection": "1.0.0-beta2", "Microsoft.Framework.DependencyInjection.Autofac": "1.0.0-beta3-10754"
之后,错误变成了:
System.DllNotFoundException: httpapi.dll at (wrapper managed-to-native) Microsoft.Net.Http.Server.UnsafeNclNativeMethods/HttpApi:HttpInitialize (Microsoft.Net.Http.Server.UnsafeNclNativeMethods/HttpApi/HTTPAPI_VERSION,uint,void*) at Microsoft.Net.Http.Server.UnsafeNclNativeMethods+HttpApi.InitHttpApi (UInt16 majorVersion, UInt16 minorVersion) [0x00000] in <filename unknown>:0 at Microsoft.Net.Http.Server.UnsafeNclNativeMethods+HttpApi..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at Microsoft.Net.Http.Server.WebListener..ctor (ILoggerFactory factory) [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Server.WebListener.ServerFactory.Initialize (IConfiguration configuration) [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Hosting.HostingEngine.InitalizeServerFactory (Microsoft.AspNet.Hosting.HostingContext context) [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Hosting.HostingEngine.Start (Microsoft.AspNet.Hosting.HostingContext context) [0x00000] in <filename unknown>:0