应用程序启动前的初始化方法...运行WebActivatorEx.ActivationManager-调用的目标引发了异常

时间:2019-02-17 20:02:07

标签: c# asp.net-mvc visual-studio azure-web-sites unity-container

通常在更改正在运行的ASP.NET MVC Azure Web服务应用程序上的web.config之后,我总是收到此错误。它将第一次运行良好,但是在更改web.config之后重新编译后,通常会出现这种情况。我认为有时是通过启动和停止Web应用程序来实现的。使它消失的唯一方法是再次将应用程序从Visual Studio发布到Azure。

Method not found: 'Microsoft.Practices.Unity.IUnityContainer MyProject.Core.ContainerManager.GetConfiguredContainer()'.    

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

Source File: D:\MyProject-master\src\MyProject.Web\App_Start\UnityMvcActivator.cs    Line: 73 

StackTrace

MissingMethodException: Method not found:   
'Microsoft.Practices.Unity.IUnityContainer 
MyProject.Core.ContainerManager.GetConfiguredContainer()'.]
MyProject.Web.App_Start.UnityWebActivator.Start() in D:\MyProject-master\src\MyProject.Web\App_Start\UnityMvcActivator.cs:73

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   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) +350
   WebActivatorEx.ActivationManager.Run() +78

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

 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): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
 System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10075124
 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95


 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

这个问题似乎非常接近我的问题,但是我没有得到这个解决方案的帮助,我的解决方案中有两个项目使用RegisterTypes方法:

interface and cannot be constructed on Unity config

这些问题是相关的,但不完全是这个问题:

https://stackoverflow.com/questions/21078380/webactivatorex-dll-unity-bootstrap-is-firing-on-a-different-project

ActivationManager Exception during build process?

Unity Bootstrapper from NuGet is throwing error on App_Start

编辑:如果在部署过程中将应用程序合并到单个程序集中,该问题似乎不再发生。

2 个答案:

答案 0 :(得分:1)

安装软件包Microsoft.AspNet.WebHelpers

答案 1 :(得分:0)

对我来说,结果证明这是一个问题,我试图将空值注入需要值的东西中——实际上与错误没有任何关系。例如,我缺少一个配置设置,它试图在某处注入该缺少的设置。一旦我意识到哪个注入出了问题并修复了它,错误就消失了。