2011-11-15 15 views
20

Me estoy poniendo la siguiente excepción cuando construcción de un proyecto de sitio web en VS 2010:ActivationManager Excepción durante el proceso de compilación?

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ómo hago para la depuración de esto? Está sucediendo cuando construyo en VS.NET y desde la línea de comandos (por ejemplo, a través de NAnt/MSBuild).

+0

¿Alguna de las respuestas funcionó para usted? –

Respuesta

2

Aumente el nivel de detalle de la tarea msbuild o línea de comando para obtener mensajes de error más detallados.

Por ejemplo, use /verbosity:detailed.

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

¿Está utilizando Ninject?
Si es así, consulte la siguiente: http://groups.google.com/group/ninject/browse_thread/thread/1934e9260ba07ecd?pli=1 y esto: http://www.techques.com/question/1-6173194/Strange-behaviour-when-using-Ninject-to-resolve-a-service-within-a-controller-factory

¿Está utilizando RavenDB?
Si es así, consulte la siguiente: http://groups.google.com/group/ravendb/browse_thread/thread/437738caf4760ce1/b7e92fd6cfeaaa17?#b7e92fd6cfeaaa17

23

Para solucionar esto, es necesario proporcionar el argumento -errorstack a la aspnetcompiler. Luego, cuando falle, obtendrá no solo el rastro de pila de la excepción que está viendo ahora, sino también la InnerException que está envolviendo. Por ejemplo, aquí está la salida cuando el error de generación es causada por un problema con un videocasete no dll ser cargado:

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

Para guardar futuros buscadores, puede hacer esto ejecutando 'aspnet_compiler.exe -errorstack -p C: \ physical \ path \ a \ MyApp -v MyApp' – neontapir

+2

aspnet_compiler.exe ubicación:' C \ Windows \ microsoft.net \ framework \ \ aspnet_compiler.exe' –

+0

Más información sobre los parámetros de línea de comandos: https://msdn.microsoft.com/en-us/library/ms229863(v=vs.140).aspx –

5

me gustaría a voto la respuesta de Xoltar, pero esta es mi primera contribución a tan tan No tengo el representante!

que tenía un problema muy similar en nuestro acumulación servidor (TeamCity), aquí está un clip de la acumulación de registro:

[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 

Para diagnosticar el problema me encontré ASPNET_COMPILER, utilizando el -errorstack argumento en contra de lo que MSBUILD había generado para el sitio. En este caso:

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.. 

En mi caso una dependencia de uno de los conjuntos de Azure (que no se ha instalado en el servidor de compilación) fue la raíz del problema.

1

En mi caso, estaba viendo el mensaje [AspNetCompiler] error ASPRUNTIME error message: Value cannot be null. en TeamCity.

En los registros construcción completa, el mensaje más útil en la parte inferior fue:

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. 

como resulta que tenía una excepción ser arrojado por un método que había definido usando 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 
     } 
    } 
} 

La causa en mi caso era que mi método de preinicio era cargar configuraciones del registro, y no existían en el servidor de compilación (pero sí en mi máquina, así que funcionó cuando lo construí). No tengo idea de por qué los proyectos de despliegue web ejecutan este código.

Envolví todo el asunto en un intento ..catch que registra un mensaje fatal (que en mi aplicación va tanto al archivo de registro como al registro de eventos de Windows). En construcciones, realmente no me importa si falla, ya que no necesita hacer nada. En las instalaciones reales, si falta la configuración, la aplicación no funcionará (y el registro explica por qué).


Ahora, para el OP parece que el problema está en el activador web. No me sorprendería que exista un método que use webactivor en la carpeta App_Start que arroja el error, que hace que parezca que proviene de WebActivator. Verifique primero, ajuste las cosas en try..catch si es necesario. También es posible que haya un error en el webactivator en sí.


Así que porque me encontré con esta publicación mientras investigaba el problema, con suerte esta información es útil al menos para alguien más.

TL; DR: los proyectos de implementación web ejecutan los métodos ApplicationPreStart cuando compilan. Asegúrese de tener try..catch blocks alrededor de cualquier código ejecutado en el tiempo de preinicio o de lo contrario puede manejar la situación donde se ejecuta el código durante el tiempo de compilación en su servidor (s) de compilación, fuera del entorno IIS/hosting.

Cuestiones relacionadas