构建过程中的ActivationManager异常?

mtu*_*tty 21 asp.net

在VS 2010中构建网站项目时,我遇到以下异常:

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..     
Run Code Online (Sandbox Code Playgroud)

我该如何调试呢?当我使用VS.NET和命令行(例如,通过NAnt/MSBuild)构建时,就会发生这种情况.

Bry*_*ler 23

要解决此问题,您需要将-errorstack参数提供给aspnetcompiler.然后当它失败时,你不仅会得到你现在看到的异常的堆栈跟踪,而且还会得到它包装的InnerException.例如,这是构建错误是由未加载Cassette 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)
Run Code Online (Sandbox Code Playgroud)

  • 为了节省未来的求职者,您可以通过运行`aspnet_compiler.exe -errorstack -p C:\ physical\path\to\MyApp -v MyApp`来实现此目的. (16认同)
  • aspnet_compiler.exe位置:`C\Windows\microsoft.net\framework\<版本>\aspnet_compiler.exe` (2认同)

Dav*_*tts 5

我想向Xoltar的答案进行投票,但这是我对SO的第一次贡献,所以我没有代表!

我的构建服务器(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
Run Code Online (Sandbox Code Playgroud)

为了诊断问题我运行了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..
Run Code Online (Sandbox Code Playgroud)

在我的情况下,一个Azure程序集(它没有安装在构建服务器上)的依赖是问题的根源.


Ram*_* A. 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-使用 Ninject 解析控制器工厂内的服务时的行为

你在使用RavenDB吗?
如果是这样,请参阅:http://groups.google.com/group/ravendb/browse_thread/thread/437738caf4760ce1/b7e92fd6cfeaaa17 ?#b7e92fd6cfeaaa17