1

I'm using Glimpse (1.8.6) in a SharePoint provider hosted add-in with an ASP.NET MVC application. At one place we're using a SharePoint remote event receiver, which is a call from SharePoint into our ASP.NET 5 application, into which we use Postal to render and send an email.

This leads to the following NullReference exception:

at Glimpse.AspNet.AspNetFrameworkProvider.get_HttpRequestStore()
at Glimpse.Core.Framework.Factory.<>c__DisplayClass5.<InstantiateRuntimePolicyStrategy>b__4()
at Glimpse.Core.Extensions.AlternateMethodContextExtensions.TryProceedWithTimer(IAlternateMethodContext context, TimerResult& timerResult)
at Glimpse.Core.Extensibility.AlternateMethod.NewImplementation(IAlternateMethodContext context)
at Glimpse.Core.Extensibility.AlternateTypeToCastleInterceptorAdapter.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IDependencyResolverProxy.GetServices(Type serviceType)
at System.Web.Mvc.DependencyResolverExtensions.GetServices[TService](IDependencyResolver resolver)
at System.Web.Mvc.MultiServiceResolver.GetCombined[TService](IList`1 items, IDependencyResolver resolver)
at System.Web.Mvc.ViewEngineCollection.get_CombinedItems()
at System.Web.Mvc.ViewEngineCollection.Find(Func`2 lookup, Boolean trackSearchedPaths)
at System.Web.Mvc.ViewEngineCollection.Find(Func`2 cacheLocator, Func`2 locator)
at System.Web.Mvc.ViewEngineCollection.FindView(ControllerContext controllerContext, String viewName, String masterName)
at Postal.EmailViewRenderer.CreateView(String viewName, ControllerContext controllerContext)
at Postal.EmailViewRenderer.Render(Email email, String viewName)
at Postal.EmailService.CreateMailMessage(Email email)
at Postal.EmailService.Send(Email email)
at CallSite.Target(Closure , CallSite , EmailService , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
at MyWebApp.Services.MyRemoteEventReceiver.DoSomething(SPRemoteEventProperties properties) in d:\Repos\MyRemoteEventReceiver.svc.cs:line 331
at SyncInvokeProcessEvent(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

Since this request is not triggered from a call from the users browser but from SharePoint to the ASP.NET application System.Web.HttpContext.Current is null. Postal on the other hand uses Razor to render the email and therefore triggers the Glimpse interceptor.

Is there any possibility to disable Glimpse for this specific code block?

Implementing a custom IRuntimePolicy doesn't seem to be a possiblity since it won't be called in this case. The workaround provided in this question neither, since System.Web.HttpContext.Current is null in SharePoint remote event receivers. I also tried to blacklist the URL of the remote event receiver with the following code, but Glimpse still seems to be called (the remote event receiver is in a directory called Services):

<runtimePolicies>
  <uris>
    <add regex=".*\/Services\/.*"/>
  </uris>
</runtimePolicies>

With defaultRuntimePolicy="Off" the code works.

Community
  • 1
  • 1
Pascal Berger
  • 4,262
  • 2
  • 30
  • 54

1 Answers1

1

The regex runtime policy just stops Glimpse from storing the data gathered, but as you can see from your call stack, it doesn't stop the interceptor from watching the request.

You can disable that by adding this to your config's <glimpse> node:

<inspectors>
    <ignoredTypes>
        <add type="Glimpse.Mvc.Inspector.ViewEngineInspector, Glimpse.Mvc3" />
    </ignoredTypes>
</inspectors>
nikmd23
  • 9,095
  • 4
  • 42
  • 57
  • Thanks! But I assume this will completely disable ViewEngine inspection. I would like to have it enabled for the whole project except for one code block in the remote event receiver. – Pascal Berger May 24 '16 at 15:44
  • You are correct. Unfortunately, there isn't a way to do that. :( – nikmd23 May 25 '16 at 16:54