2012-04-04 19 views
13

我在部署在appharbor上的MVC 3項目上使用Ninject。我注意到當應用程序啓動時出現異常,它看起來像Ninject內部的東西是原因,但我找不到任何答案 - 所以請幫助我:)Ninject在appharbor上的應用程序啓動時崩潰

將嘗試添加完整的異常這裏:

Server Error in '/' Application. 

Object reference not set to an instance of an object. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.] 
    NewRelic.Agent.Core.AgentShim.GetTracer(String tracerFactoryName, UInt32 level, String metricName, String assemblyName, String className, String methodName, String argumentSignature, Object invocationTarget) +51 
    System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info) +99 
    Ninject.Modules.AssemblyNameRetriever.CreateTemporaryAppDomain() in c:\Projects\Ninject\ninject\src\Ninject\Modules\AssemblyNameRetriever.cs:68 
    Ninject.Modules.AssemblyNameRetriever.GetAssemblyNames(IEnumerable`1 filenames, Predicate`1 filter) in c:\Projects\Ninject\ninject\src\Ninject\Modules\AssemblyNameRetriever.cs:47 
    Ninject.Modules.CompiledModuleLoaderPlugin.LoadModules(IEnumerable`1 filenames) in c:\Projects\Ninject\ninject\src\Ninject\Modules\CompiledModuleLoaderPlugin.cs:81 
    Ninject.Modules.ModuleLoader.LoadModules(IEnumerable`1 patterns) in c:\Projects\Ninject\ninject\src\Ninject\Modules\ModuleLoader.cs:60 
    Ninject.KernelBase.Load(IEnumerable`1 filePatterns) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:236 
    Ninject.KernelBase..ctor(IComponentContainer components, INinjectSettings settings, INinjectModule[] modules) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:97 
    Ninject.KernelBase..ctor(INinjectModule[] modules) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:57 
    Ninject.StandardKernel..ctor(INinjectModule[] modules) in c:\Projects\Ninject\ninject\src\Ninject\StandardKernel.cs:46 
    Checkin.App_Start.NinjectWebCommon.CreateKernel() in d:\temp\44uvjuob.32m\input\Checkin\App_Start\NinjectWebCommon.cs:43 
    Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:50 
    Checkin.App_Start.NinjectWebCommon.Start() in d:\temp\44uvjuob.32m\input\Checkin\App_Start\NinjectWebCommon.cs:26 

[TargetInvocationException: Exception has been thrown by the target of an invocation.] 
    System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0 
    System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +69 
    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +242 
    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +21 
    System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19 
    WebActivator.BaseActivationMethodAttribute.InvokeMethod() +223 
    WebActivator.ActivationManager.RunActivationMethods() +493 
    WebActivator.ActivationManager.RunPreStartMethods() +28 
    WebActivator.ActivationManager.Run() +55 

[InvalidOperationException: 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..] 
    System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +377 
    System.Web.Compilation.BuildManager.CallPreStartInitMethods() +267 
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +690 

[HttpException (0x80004005): 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..] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +532 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +172 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272 

如果我重新加載頁面 - 異常消失。 這可能有些事情要使用ninject一個過濾器:

this.BindFilter<AdminAuthorizationAttribute>(FilterScope.Controller, -100) 
    .When((context, ad) => context.RouteData.DataTokens["area"] != null && 
      ((string)context.RouteData.DataTokens["area"]).ToLower() == "admin" && 
      ((string)context.RouteData.Values["controller"]).ToLower() != "login"); 
+0

即使我一直對此感到困惑。是什麼讓你認爲它的Ninject正在崩潰?如果你拿出過濾器,它會消失嗎? – Mrchief 2012-04-04 14:55:53

+0

也收到此錯誤。也可能是新的遺物,因爲我在appharbor和裝有新文物的Windows 2008服務器上都得到了這個。 ninject 2.2和3.0都有。 – terjetyl 2012-04-04 17:13:44

+0

從堆棧跟蹤('NewRelic.Agent.Core.AgentShim.GetTracer')看起來NewRelic是造成這個問題的原因... – nemesv 2012-04-04 18:53:30

回答

13

的問題不是由Ninject造成的。它是NewRelic.Agent.Core.AgentShim(由AppHarbor使用),是罪魁禍首。

雖然看着堆棧跟蹤,我想你可以通過禁用Ninject的自動extenison加載功能並手動加載它們來解決這個問題。

var kernel = new StandardKernel(new NinjectSettings { LoadExtensions = false }) 
kernel.Load(new Ninject.Web.Mvc.MvcModule()); // same for all other extension modules 
+0

我曾試過這個,但它沒有解決我的問題。即使LoadExtensions = false – 2012-04-09 19:42:52

+0

@JessChadwick,我仍然會遇到異常,這僅僅是問題中堆棧跟蹤的解決方法。如果完全按照上面的方式完成,它將解決該堆棧跟蹤。要麼你有一個不同的問題,或者你在創建內核之後將LoadExtension設置爲false(kernel.Settings.LoadExtensions = false)。這不起作用。如果您有其他問題,則可能需要等到AppHarbor解決問題。 – 2012-04-09 21:57:27

+0

@RemoGloor,nope - 我已經得到完全相同的堆棧跟蹤,並像上例中那樣設置LoadExtensions屬性。看起來我只需要等AppHarbor修復。 – 2012-04-10 13:38:23

1

我們已經暫時禁用了New Relic插件並從AppHarbor服務器中刪除了New Relic代理。一旦它不再對平臺上運行的應用程序造成問題,我們將重新添加New Relic。