1

I'm trying to set up Raygun.io on a WCF service, and despite the simple instructions on the site, am having little luck getting things running.

I've signed up for my account, installed the Mindscape.Raygun4Net package via Nuget, then tried the following methods:

Web.config approach: I added the config section, the Raygun section with my affiliate key, then added the module under system.webserver. Nothing was logged.

Global.asax approach: I tried adding a RaygunClient object to global.asax and then sending the exception on Application_Error. Nothing was logged and the breakpoint inside Application_Error was never hit.

IErrorHandler Approach: This one actually got the errors logging to Raygun, but had its own issues:

Error Handler:

public class RaygunLogger : IErrorHandler
{
    private RaygunClient _client = new RaygunClient("5xqBOzTBrzIsS++3vsbFZw==");
    public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
    {

    }

    public bool HandleError(Exception error)
    {
        _client.Send(error);
        return false;
    }
}

Behavior:

public class RaygunServiceBahavior : IServiceBehavior
{

    public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints,
        BindingParameterCollection bindingParameters)
    {
    }

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
        IErrorHandler errorHandler = new RaygunLogger();

        foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
        {
            channelDispatcher.ErrorHandlers.Add(errorHandler);
        }
    }

    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {

    }
}

Behavior Extension:

public class RaygunBehaviorExtensionElement : BehaviorExtensionElement
{
    public override Type BehaviorType
    {
        get { return typeof(RaygunServiceBahavior); }
    }

    protected override object CreateBehavior()
    {
        return new RaygunServiceBahavior();
    }
}

The exception would be thrown, then the Handle_Error method would be called, sending the error to Raygun, but it always sends two exceptions instead of one. The first exception is an ObjectDisposedException: The message object has been disposed.

Has anyone had luck setting up Raygun on WCF? If so, do you have the same behavior or can you see anything I'm doing differently?

Maloric
  • 5,525
  • 3
  • 31
  • 46

1 Answers1

0

I tried doing something very similar and ended up with my IErrorHandler's HandleError() method re-entrant, originating from Mindscape.Raygun4Net.Builders.RaygunRequestMessageBuilder.GetIpAddress(HttpRequest request)

Rather than an object disposed exception it caused a System.Argument exception:

   at System.ServiceModel.Dispatcher.ErrorBehavior.HandleErrorCommon(Exception error, ErrorHandlerFaultInfo&amp;amp; faultInfo)</StackTrace><ExceptionString>System.ArgumentException: Value does not fall within the expected range.
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
   at System.Web.HttpRequest.AddServerVariableToCollection(String name)
   at System.Web.HttpRequest.FillInServerVariablesCollection()
   at System.Web.HttpServerVarsCollection.Get(String name)
   at Mindscape.Raygun4Net.Builders.RaygunRequestMessageBuilder.GetIpAddress(HttpRequest request)

I don't have a solution yet, however.

Nathan Lewis
  • 184
  • 2
  • 9
  • 1
    This was fixed in Raygun4Net version 4.2.1. Putting a raygun hook in as posted above should work fine now. This particular bug was reported here: https://raygun.io/forums/thread/17338#17488 Another related exception was fixed in Raygun4net 5.0.1 as reported here: https://raygun.io/forums/thread/19164#19781 – Nathan Lewis Apr 27 '15 at 05:07