Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3855764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:49:35+00:00 2026-05-19T17:49:35+00:00

I just noticed something particular. I have an internal stock service which is published

  • 0

I just noticed something particular. I have an internal stock service which is published through basicHttpBinding, and a customBinding (http+binary) for which metadata is enabled. I also included a mex endpoint for http. We use Visual Studio 2008 & VB.NET

Just recently we noticed that we were unable to succesfully add a service reference to this service in our other projects. All that it would generate was the first custom exception we included through a FaultContract (actually, there was only 1 type). if I’d add a simple web reference it would work correctly as well. Also, the WcfClient.exe had no problems either in loading the services. Just VS.NET add service reference wouldn’t work.

In the service this exception inherits from Exception and is marked as serializable. That’s all you’re supposed to do, no?

Anyway, this had me baffled. If I remove the FaultContract for this custom exception everything works fine. I can add a service reference, no problem. But is there a way I can still have my custom exceptions? Is this a known problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:49:35+00:00Added an answer on May 19, 2026 at 5:49 pm

    I ran into this myself today. The solution was to use an object not inheriting from Exception in the FaultContract. If you look at the MSDN docs for FaultException and FaultContract you will see that the official examples use plain classes (with DataContact attributes) rather than classes extending Exception for FaultException.Detail. I’m not sure why Exception causes the Add Service Reference to fail, but I suspect it has to do with the serializing or retrieving the type information for custom exceptions. I have included before and after example implementations to demonstrate the working approach.

    Before (didn’t work):

    [ServiceContract]
    public interface IMyService
    {
        [OperationContract]
        [FaultContract(typeof(MyException))]
        MyResults MyServiceOperation(string myParameter);
    }
    
    [Serializable]
    public class MyException : Exception
    {
        public string CustomData { get; set; }
    }
    
    [ErrorHandlerBehavior(typeof(MyErrorHandler))]
    public class MyService : IMyService
    {
        public MyResults MyServiceOperation(string myParameter)
        {
            ...
            throw new MyModelException { CustomData = "42" };
            ...
        }
    }
    
    public class MyErrorHandler : IErrorHandler
    {
        public bool HandleError(Exception error) { return false; }
    
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            try { throw error; }
            catch (MyModelException ex)
            {
                var faultEx = new FaultException<MyException>(new MyException { CustomData = ex.CustomData });
                fault = Message.CreateMessage(version, faultEx.CreateMessageFault(), faultEx.Action);
            }
            catch { /* Supress all others */ }
        }
    }
    

    After (worked):

    [ServiceContract]
    public interface IMyService
    {
        [OperationContract]
        [FaultContract(typeof(MyFault))]
        MyResults MyServiceOperation(string myParameter);
    }
    
    [DataContract]
    public class MyFault
    {
        [DataMember]
        public string CustomData { get; set; }
    }
    
    [ErrorHandlerBehavior(typeof(MyErrorHandler))]
    public class MyService : IMyService
    {
        public MyResults MyServiceOperation(string myParameter)
        {
            ...
            throw new MyModelException { CustomData = "42" };
            ...
        }
    }
    
    public class MyErrorHandler : IErrorHandler
    {
        public bool HandleError(Exception error) { return false; }
    
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            try { throw error; }
            catch (MyModelException ex)
            {
                var faultEx = new FaultException<MyFault>(new MyFault { CustomData = ex.CustomData });
                fault = Message.CreateMessage(version, faultEx.CreateMessageFault(), faultEx.Action);
            }
            catch { /* Supress all others */ }
        }
    }
    

    Source: Max Strini for the use of his code and help in finding the solution to this issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just noticed something strange. If I have this XML: <level number=7 background=background_5> and
I just want to confirm something I noticed when downloading a file through sftp
i have just noticed something strange in some asp.net markup. I have a standard
Possible Duplicate: Puzzling Enumerable.Cast InvalidCastException Hi, I just noticed something quite strange with the
Let me start from a real life example: Customer: Alex, just noticed something strange
I just noticed that say http://s7.addthis.com/js/250/addthis_widget.js#pub=PUBID does the equivalent of http://s7.addthis.com/js/250/addthis_widget.js?pub=fct-250 but is much
I've just noticed something that I'd never noticed before, while working on a (regular,
I've just noticed something interesting with my UIButton. I'm currently fading the button out
OK, I realize that question might seem weird, but I just noticed something that
I've just noticed that something terrible is missing in jquery-ui. A way to rotate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.