2012-04-04 4 views
13

Я использую Ninject для моего проекта MVC 3, развернутого на appharbor. Я заметил, что я получаю исключение, когда приложение запускается, и похоже, что что-то внутри 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

+0

Также получаю эту ошибку. Также может быть новая реликвия, поскольку я получаю это как на appharbor, так и на сервере Windows 2008 с установленной новой реликвией. Как с ninject 2.2, так и с 3.0. – terjetyl

+0

Из трассировки стека ('NewRelic.Agent.Core.AgentShim.GetTracer') кажется, что NewRelic вызывает проблему ... – nemesv

ответ

13

Проблема не вызваны Ninject. Это преступник NewRelic.Agent.Core.AgentShim (используемый AppHarbor).

Несмотря на то, что, глядя на стекловидную структуру, я думаю, что вы можете обойти эту проблему, отключив функцию автоматической экстензивной загрузки Ninject и загрузите ее вручную.

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

Я пробовал это, но это не решило мою проблему. Я все еще получаю исключение, даже с LoadExtensions = false –

+0

@JessChadwick Это всего лишь обходное решение для именно stacktrace в вопросе. Он решит, что stacktrace будет выполняться точно так же, как указано выше. Либо у вас другая проблема, либо вы устанавливаете LoadExtension в false после создания ядра (kernel.Settings.LoadExtensions = false). Это не будет работать. Если у вас другая проблема, вам, вероятно, придется подождать, пока AppHarbor устранит проблему. –

+0

@RemoGloor, nope. У меня точно такая же трассировка стека и настройка свойства LoadExtensions так же, как в приведенном выше примере. Похоже, мне просто нужно ждать, пока AppHarbor исправит. –

1

Мы временно отключили надстройку New Relic и удалили агент Relic с серверов AppHarbor. Мы снова добавим новую реликвию, если она больше не вызывает проблем для приложений, запущенных на платформе.