2011-11-15 24 views
20

我得到以下異常時建設一個網站項目在VS 2010:構建過程中的ActivationManager異常?

The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..  

如何去調試呢?當我使用VS.NET和命令行(例如,通過NAnt/MSBuild)構建時,就會發生這種情況。

+0

是否有任何答案適合您? –

回答

2

提高msbuild任務或命令行的詳細級別以獲取更詳細的錯誤消息。例如,使用/verbosity:detailed

http://msdn.microsoft.com/en-us/library/ms164311.aspx

是否使用Ninject?
如果是這樣,看到這個:http://groups.google.com/group/ninject/browse_thread/thread/1934e9260ba07ecd?pli=1和這個:http://www.techques.com/question/1-6173194/Strange-behaviour-when-using-Ninject-to-resolve-a-service-within-a-controller-factory

你使用的是RavenDB嗎?
如果是這樣,請參閱本:http://groups.google.com/group/ravendb/browse_thread/thread/437738caf4760ce1/b7e92fd6cfeaaa17?#b7e92fd6cfeaaa17

23

爲了解決這個問題,你需要將-errorstack參數提供給aspnetcompiler。然後,當它失敗時,您不僅會得到您現在看到的異常的堆棧跟蹤,還會收到它正在包裝的InnerException。舉例來說,這裏是當編譯錯誤是由一個盒中的問題引起的DLL沒有被加載輸出:

error ASPRUNTIME: The pre-application start initialization method Run on type We 
bActivator.ActivationManager threw an exception with the following error message 
: Exception has been thrown by the target of an invocation.. 

[TypeLoadException]: Could not load type 'Cassette.Configuration.ICassetteConfig 
uration' from assembly 'Cassette, Version=0.8.1.0, Culture=neutral, PublicKeyTok 
en=null'. 
    at Cassette.Web.StartUp..cctor() 

[TypeInitializationException]: The type initializer for 'Cassette.Web.StartUp' t 
hrew an exception. 
    at Cassette.Web.StartUp.PreApplicationStart() 

[TargetInvocationException]: Exception has been thrown by the target of an invoc 
ation. 
    at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Ob 
ject target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAt 
tributes, RuntimeType typeOwner) 
    at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Obj 
ect target, Object[] arguments, Signature sig, MethodAttributes methodAttributes 
, RuntimeType typeOwner) 
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke 
Attr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisib 
ilityChecks) 
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke 
Attr, Binder binder, Object[] parameters, CultureInfo culture) 
    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) 
    at WebActivator.BaseActivationMethodAttribute.InvokeMethod() 
    at WebActivator.ActivationManager.RunActivationMethods[T]() 
    at WebActivator.ActivationManager.RunPreStartMethods() 
    at WebActivator.ActivationManager.Run() 

[InvalidOperationException]: The pre-application start initialization method Run 
on type WebActivator.ActivationManager threw an exception with the following er 
ror message: Exception has been thrown by the target of an invocation.. 
    at System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection` 
1 methods) 
    at System.Web.Compilation.BuildManager.CallPreStartInitMethods() 
    at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appMan 
ager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, Host 
ingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception a 
ppDomainCreationException) 

[HttpException]: The pre-application start initialization method Run on type Web 
Activator.ActivationManager threw an exception with the following error message: 
Exception has been thrown by the target of an invocation.. 
    at System.Web.Compilation.ClientBuildManager.EnsureHostCreated() 
    at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuil 
dManagerCallback callback, Boolean forceCleanBuild) 
    at System.Web.Compilation.Precompiler.Main(String[] args) 
+16

爲了節省將來的搜索者,你可以通過運行'aspnet_compiler.exe -errorstack -p C:\ physical \ path \ to \ MyApp -v MyApp'來達到此目的。 – neontapir

+2

aspnet_compiler.exe位置:'C \ Windows \ microsoft.net \ framework \ \ aspnet_compiler.exe' –

+0

有關命令行參數的更多信息:https://msdn.microsoft.com/en-us/library/ms229863(v=vs.140).aspx –

5

我想贊成票Xoltar的答案,但是這是我的第一個貢獻如此如此我沒有代表!

我有我們的構建服務器(TeamCity的)一個非常類似的問題,這裏是從構建日誌剪輯:

[00:10:39]: (MvcBuildViews target) -> 
[00:10:39]: error ASPRUNTIME : The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation.. [C:\TeamCity\buildAgent\work\1ee8c94c32e676ad\source\Project.Site\Project.Site.csproj] 
[00:10:39]:  0 Warning(s) 
[00:10:39]:  1 Error(s) 
[00:10:39]: Time Elapsed 00:00:27.93 

要診斷我跑ASPNET_COMPILER問題,使用-errorstack反對什麼MSBUILD爲網站生成的參數。在這種情況下:

C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_compiler -p "C:\TeamCity\buildAgent\work\1ee8c94c32e676ad\source\Project.Site" -v anything -errorstack 

Utility to precompile an ASP.NET application 
Copyright (C) Microsoft Corporation. All rights reserved. 

error ASPRUNTIME: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message : Exception has been thrown by the target of an invocation.. 

[FileNotFoundException]: Could not load file or assembly 'msshrtmi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 
    at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment() 
    at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor() 

error ASPRUNTIME: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message : Exception has been thrown by the target of an invocation.. 

在我的情況下對Azure的組件(這是不是在構建服務器上安裝)之一的依賴是問題的根源。

1

就我而言,我在TeamCity中看到消息[AspNetCompiler] error ASPRUNTIME error message: Value cannot be null.

在完全構建日誌,在底部的更有用的信息是:

error ASPRUNTIME : The pre-application start initialization method InitializePreStart on type MyApplication.MvcApplication threw an exception with the following error message: Value cannot be null. 

事實證明我有一個例外,通過使用PreApplicationStartMethod我已經定義的方法被拋出:

[assembly: System.Web.PreApplicationStartMethod(typeof(MyApp.MvcApplication), "InitializePreStart")] 

namespace PrintFleet.PFE.RestService 
{ 
    public class MvcApplication : System.Web.HttpApplication 
    { 
     //.... 
     public static void InitializePreStart() 
     { 
      // exception thrown here 
     } 
    } 
} 

在我的情況下,原因是我的prestart方法是從註冊表中加載設置,並且它們不存在於構建服務器上(但是在我的機器上,因此它在我構建它時運行)。我不知道爲什麼webdeployment項目運行此代碼。

我把所有的東西都包裹在一起..趕上記錄一條致命的消息(在我的應用程序中,它會同時記錄日誌文件和Windows事件日誌)。在構建中,我不在乎它是否失敗,因爲它不需要做任何事情。在實際安裝中,如果設置丟失,應用程序將無法工作(因此日誌解釋了原因)。


現在,OP的問題似乎是在網絡激活器。如果在App_Start文件夾中存在一個使用webactivor的方法來拋出錯誤,這使得它看起來像來自WebActivator,我不會感到驚訝。首先在那裏檢查,如果需要的話,在try..catch中包裝一些東西。也有可能是webactivator本身存在一個bug。


因爲我在研究這個問題時遇到了這篇文章,所以希望這個信息對至少別人有用。

TL; DR:Web部署項目在編譯時運行ApplicationPreStart方法。確保在預啓動時運行任何代碼時都有try..catch塊,否則可以處理代碼在編譯時在IIS /宿主環境之外的構建服務器上執行的情況。