【问题标题】:The pre-application start initialization method... Run WebActivatorEx.ActivationManager - Exception has been thrown by the target of an invocation应用程序启动前初始化方法... Run WebActivatorEx.ActivationManager - 调用的目标已抛出异常
【发布时间】:2019-02-17 20:02:06
【问题描述】:

我经常收到此错误,通常是在更改正在运行的 ASP.NET MVC azure Web 服务应用程序上的 web.config 之后。它会在第一次运行良好,但在更改 web.config 后重新编译后,通常会出现这种情况。我认为有时只需启动和停止网络应用程序就会发生这种情况。我可以让它消失的唯一方法是再次将应用程序从 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 

堆栈跟踪

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

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

【问题讨论】:

  • “找不到方法”通常是由部署问题引起的。您有一段代码希望(在运行时动态地)找到某个 dll 的版本,并且只有旧(或新)版本可用。当使用注入/反转技术(例如统一)时,通常会加剧此类问题。编译器可以在编译时强制执行的东西在运行时中断。
  • 它最初在部署后运行。然后一段时间后出现错误。我不明白为什么它首先可以在部署中运行然后发生错误。
  • @SimonMourier 您建议如何部署它来避免这种情况?它也发生在 Visual Studio 中本地运行。这是不一致的,但通常发生在对代码进行多次编辑或首次打开 IDE 并运行项目时。 “解决方案干净”总是可以解决它。除了完全删除 DI 之外,我还没有找到任何关于如何解决这个问题的信息。当我搜索错误时,什么也没有出现。
  • 这真的取决于您部署程序集的方式,没有灵丹妙药。所有 DI 技术都假定二进制部署处于“正常”状态。您可以做的是在 Visual Studio 项目中添加构建后事件以将新程序集复制到它们应该驻留的位置(您还可以编辑 msbuild csproj 文件以添加一些自定义复制或同步步骤)。

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


【解决方案1】:

安装包 Microsoft.AspNet.WebHelpers

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多