سؤال

I'm using Nancy MVC and Nancy.Elmah. Currently, there's a bug in Nancy that raises an exception for requests with accept headers of "*". Here's the Elmah log:

  System.ArgumentException
  inputString not in correct Type/SubType format Parameter name: *

  System.ArgumentException: inputString not in correct Type/SubType format
  Parameter name: *
     at Nancy.Responses.Negotiation.MediaRange.FromString(String contentType)
     at Nancy.Routing.DefaultRouteInvoker.<>c__DisplayClass5a.<>c__DisplayClass5c.<GetCompatibleHeaders>b__4f(MediaRange mr)
     at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
     at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
     at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
     at Nancy.Routing.DefaultRouteInvoker.GetCompatibleHeaders(IEnumerable`1 coercedAcceptHeaders, NancyContext context, Negotiator negotiator)
     at Nancy.Routing.DefaultRouteInvoker.ProcessAsNegotiator(Object routeResult, NancyContext context)
     at Nancy.Routing.DefaultRouteInvoker.InvokeRouteWithStrategy(Object result, NancyContext context)
     at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
     at CallSite.Target(Closure , CallSite , DefaultRouteInvoker , Object , NancyContext )
     at Nancy.Routing.DefaultRouteInvoker.Invoke(Route route, DynamicDictionary parameters, NancyContext context)
     at Nancy.Routing.DefaultRequestDispatcher.Dispatch(NancyContext context)
     at Nancy.NancyEngine.InvokeRequestLifeCycle(NancyContext context, IPipelines pipelines)

I tried filtering it with the following web.config

<errorFilter>
  <test>
    <or>
      <regex binding="Exception" pattern="inputString not in correct Type/SubType format Parameter name: \*" />
    </or>
  </test>
</errorFilter>

But the errors are not filtered out.

Also tried binding="BaseException.Message" without luck.

I would like a way to filter these messages from being logged. Could some "correct" my filter configuration above to do so? Thanks!

هل كانت مفيدة؟

المحلول

Well, after a few more hours of trail and error I discovered the issue is that the, "Parameter name: *" portion is not part of the actual exception message. I'm guessing that the message in the log is a concatenation of the exception message and parameter values. Changed the filter as shown and it's works.

<errorFilter>
  <test>
    <regex binding="Exception.Message" pattern="inputString not in correct Type/SubType format" />
  </test>
</errorFilter>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top