none
WCF IErrorHandler does not provide Exception line numbers RRS feed

  • Question

  • Hi,

    We are adding a IErrorHandler (via common ServiceBehavior) to all WCF services, to capture unhandled exceptions.

    The problem is that even though the code is running in DEBUG (DEBUG symbols are on) and deployed with the .pdbs, when the exception makes it into

    IErroHandler.bool HandleError(Exception error) 

    it does not contain the usual debug information like line number. (in the StackTrace)

    It's important for us the have the line number otherwise it's impossible to find where the error ocured.

    Any Ideas?

    Thanks,

    Stevo

    Thursday, October 3, 2013 5:22 PM

All replies

  • Hi Stevo,

    To make it more convenient to find the root cause of the exception in WCF, you might try using some external tools, such as log4net.

    http://pieterderycke.wordpress.com/2012/09/05/logging-all-unhandled-exception-in-wcf-with-log4net/

    In addtion, you can also consider enable tracing for the service(see: Configuring Tracing) to troubleshoot errors in WCF service, and here is a Service Trace Viewer Tool which helps you analyze diagnostic traces.

    Hope this information helps.

    Best Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, October 4, 2013 5:34 AM
    Moderator
  • Hi,

    this has nothing to do with log4net or anything similar. Even while debugging and looking at the Exception StackTrace in Visual Studio, the error line numbers are not there. log4net is not going make up information that does not exist. 

    We have all of this:

    public class Log4NetErrorHandler : IErrorHandler
    {
        private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
     
        public bool HandleError(Exception error)
        {
            log.Error("An unexpected has occurred.", error);
     
            return false; // Exception has to pass the stack further
        }
     
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
        }
    }

    the problem is that the 'error' variable does not contain the debugging information.

    The problem is with .Net framework not providing the line numbers in case of a WCF IErrorHandler implemention, not with logging the error.

    Hope that explains better,

    Stevo

    Friday, October 4, 2013 9:44 AM
  • Hi, the function you required seems not achievable currently, but you may try submit a WCF feature request at http://tinyurl.com/wcfvnext and vote, to wait Microsoft add this feature for IErrorHandler. But I do not think it is much necessary for this feature, our goal is to find the root cause of the issue more efficiency, we can use some third party tool, or other workarounds to debug(e.g. some tool suggested by the moderator) to find the cause of the issue in a more convenient way.
    Sunday, October 6, 2013 12:08 PM
  •  Logging lines of code (debug information) against an Exception is one of the most basic features of any programming language. 

    Are you saying that it can't be done in WCF and you (Microsoft) does not consider it necessary?



    • Edited by Stevo Zilik Wednesday, October 9, 2013 10:20 AM
    Wednesday, October 9, 2013 10:20 AM