5

Very very rare my MVC 3 application have following exception. It is only in Release mode, and when it starts only restart of IIS application pool helps. Does anyone could give me a tip what can cause this error?

And the exception:

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Web.Mvc.FilterProviderCollection.<RemoveDuplicates>d__b.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.<ReverseIterator>d__a0`1.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at System.Web.Mvc.FilterInfo..ctor(IEnumerable`1 filters)
   at System.Web.Mvc.ControllerActionInvoker.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Piotr Stapp
  • 18,130
  • 10
  • 63
  • 104
  • 3
    @SonerGönül which part? All solution? This exception shows stack trace from asp.net MVC source code. – Piotr Stapp Sep 16 '13 at 14:40
  • 1
    And did you write or use any ActionFilters? Do you know where RemoveDuplicates comes from? – Henk Holterman Sep 16 '13 at 14:44
  • 1
    Looks like the RemoveDuplicates from a custom Filter is poping this exception! – Fals Sep 16 '13 at 14:46
  • @Fals why from **custom** filter? RemoveDuplicates is from `FilterProviderCollection` which is a MVC class – Piotr Stapp Sep 16 '13 at 15:20
  • @Garath RemoveDuplicates removes any duplicated filter in the collection. The FilterProviderCollection hold every filter in the controller, including all customs. Looks like something is messing up the List. Something is getting disposed early enougth to pop this exception. If you have a custom filter, could be the issue! – Fals Sep 16 '13 at 16:23
  • @Garath Another thing, hows your IIS config? Be sure that you are using Integrated Mode, and the correct version of the .NET Framework for the app pool! – Fals Sep 16 '13 at 16:31
  • @Fals I am sure. It happened today on ONE machine from web farm. After app pool restart everything back to normal. I have custom filters, but the do not have any static fields. For example I use `NoCache` attribute from http://stackoverflow.com/questions/1160105/asp-net-mvc-disable-browser-cache – Piotr Stapp Sep 16 '13 at 19:06
  • @Fals maybe one more thing: I know that it is probably something in my code, but I do not have an idea what could it be. – Piotr Stapp Sep 16 '13 at 19:07

1 Answers1

1

It looks like you modify the GlobalFilters collection without lock. It may happen when you access this collection for instance from IHttpModule.Init, which is called for each HttpApplication created by the runtime. Had this problem once.

Use WebActivator or simply Global_asax App_Start to init this kind of global collections.

Scooletz
  • 183
  • 2
  • 7