公司項目容器化的需要, 小編研究將net framework
項目升級成net standard 2.0
,但是在打包上傳nupkg
后,vs 的 nuget 插件不能識別依賴項,顯示 Unsupported
。
小編懷疑是公司的 nuge server 版本太低的原因,於是通過 nuget 安裝了最新的Nuget.Server
。 項目啟動后,拋500錯誤:
[FileLoadException: 未能加載文件或程序集“NuGet.Server, Version=3.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一個依賴項。找到的程序集清單定義與程序集引用不匹配。 (異常來自 HRESULT:0x80131040)]
nuget.server.App_Start.NuGetODataConfig.Start() in C:\Project_Works\github.com\nuget.server\nugetserver\App_Start\NuGetODataConfig.cs:35
[TargetInvocationException: 調用的目標發生了異常。]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +87
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +101
WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +73
WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +637
WebActivatorEx.ActivationManager.Run() +101
[InvalidOperationException: 針對類型 WebActivatorEx.ActivationManager 的應用程序預啟動初始化方法 Run 引發了異常,顯示下列錯誤消息: 調用的目標發生了異常。。]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +615
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +549
[HttpException (0x80004005): 針對類型 WebActivatorEx.ActivationManager 的應用程序預啟動初始化方法 Run 引發了異常,顯示下列錯誤消息: 調用的目標發生了異常。。]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10075596
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
因為nuget.server的程序包有問題, 最終小編下載了最新的源代碼 Nuget.Server
本地編譯運行正常,但是將發布后的web項目部署在服務器上, 項目運行返回500錯誤。
異常信息:
異常類型: NullReferenceException
異常消息: 未將對象引用設置到對象的實例。
在 NuGet.Server.ServiceResolverExtensions.Resolve[T](IServiceResolver resolver) 位置 C:\Project_Works\github.com\nuget\NuGet.Server\src\NuGet.Server\Core\ServiceResolverExtensions.cs:行號 11
在 ASP.default_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer)
在 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
在 System.Web.UI.Page.Render(HtmlTextWriter writer)
在 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
根據日志判斷:項目啟動時沒有注入相關對象,導致在進行IOC 解析的時候,出現的空指針異常。
最終在 NuGetODataConfig.cs 文件中發現了錯誤原因。將if 斷言刪除,重新發布項目,Nuget.Server 運行成功,vs 也能正常識別依賴項
// The consuming project executes this logic with its own copy of this class. This is done with a .pp file that is
// added and transformed upon package install.
#if DEBUG
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(NuGet.Server.App_Start.NuGetODataConfig), "Start")]
#endif