Link to home
Start Free TrialLog in
Avatar of Charles Baldo
Charles BaldoFlag for United States of America

asked on

C# Webservices Enum default value overide ignored

Hello I have the following enum in a class that is used in a web service

    public enum Genders
    {
      Male = 1,
      Female = 2
    }

When I reference the webservice in a c# winform I get an error if I instantiate a class that is referenced to that web sevice
 profile p = new profile();
 p.Gender = (Genders)2;

When I run the code I get "There was an error generating the XML document." the stack trace goes back to the Reference.cs file. Sure enough in the reference I have code that looks like this

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.1433")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://xxxxxxxx.net/")]
    public enum Genders {
       
        /// <remarks/>
        Male,
       
        /// <remarks/>
        Female,
    }

So it is being cause by the local reference reseting the default back to 0 when it generates. If I go in and manually change the code in the reference.cs to

    public enum Genders {
       
        /// <remarks/>
        Male=1,
       
        /// <remarks/>
        Female=2,
    }

it works. However i can not do that because when it autogenerates it wipes my changes out as soon as I update the web reference.  

Any Ideas why this is happening and what I can do to fix it?
ASKER CERTIFIED SOLUTION
Avatar of jjardine
jjardine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Charles Baldo

ASKER

I am actually using 2008 but its a RTM version and I was suspecting the same thing. I think I may abandon starting at 1 and just go with the defalt and start at zero.