6

I keep getting this error, usually after changing the web.config on a running ASP.NET MVC azure web service app. It will run fine the first time but after it recompiles after changing the web.config this is usually appearing. I think it happens sometimes by just starting and stopping the web app. The only way I can make it go away is by publishing the app again from visual studio to 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

This question seems very close to my issue but I haven't gotten this solution to work, there are two projects in my solution that use the RegisterTypes method:

interface and cannot be constructed on Unity config

These questions were related but not exactly this issue:

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

EDIT: If I merge the application into single assemblies during deployment the issue doesn't seem to happen anymore.

Heinrich
  • 1,711
  • 5
  • 28
  • 61
  • 1
    "Method not found" is often caused by a deployment issue. You have a piece of code that expects to find (dynamically, at runtime) a version of some dll, and only an older (or newer) version is available. This kind of issue is usually typically exacerbated when using injection/inversion technologies such as unity. Something that a compiler can enforce at compile time breaks here at runtime. – Simon Mourier Feb 22 '19 at 07:43
  • It runs after deployment initially. Then after some time the error appears. I don't understand why it could run at first in deployment then the error happens. – Heinrich Feb 22 '19 at 15:45
  • @SimonMourier how would you recommend deploying it to avoid this? It also happens running locally in the with Visual Studio. It's inconsistent but usually happens after several edits to code or when the IDE is first opened and the project is run. A "solution clean" always fixes it. Aside from removing DI completely which would take forever, I haven't found anything about how to fix this. Nothing comes up when I search for the error. – Heinrich May 15 '19 at 00:01
  • 1
    It really depends on the way you deploy your assemblies, there's no magic bullet. All DI technologies presume binary deployment is in an "ok" state. What you could do is add post build events in Visual Studio projects to copy the new assemblies where they should reside (you can also edit msbuild csproj files to add some custom copy or sync steps). – Simon Mourier May 15 '19 at 06:51

2 Answers2

1

Install-Package Microsoft.AspNet.WebHelpers

Felipe Bulle
  • 201
  • 2
  • 3
0

For me, this turned out to be a problem where I was trying to inject something null into something that required a value -- didn't actually have anything to do with the error. For instance, I had a configuration setting that was missing, and it was trying to inject that missing setting somewhere. Once I realized which injection was going awry and fixed it, the error went away.

codeMonkey
  • 4,134
  • 2
  • 31
  • 50