James Helms
James Helms

Reputation: 871

Same property being generated twice from web service

I am connecting to a web service. When the class is being generated it creates two of the same property, one with the System.CodeDom.Compiler.GeneratedCodeAttribute property of "System.Xml" and one with the System.CodeDom.Compiler.GeneratedCodeAttribute property of "System.Runtime.Serialization".

Example of the autogenerated class:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")] [System.Runtime.Serialization.DataContractAttribute(Name="CountryCode", Namespace="http://schemas.datacontract.org/2004/07/")] public enum CountryCode : int

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")] [System.SerializableAttribute()] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.datacontract.org/2004/07/")] public enum CountryCode

Because of this the solution won't compile and gives me the error:

CS0101: The namespace 'TAP' already contains a definition for 'CountryCode'

Any ideas would be appreciated.

Upvotes: 0

Views: 358

Answers (1)

gpmurthy
gpmurthy

Reputation: 2427

When adding the service reference make sure to the check the "Reuse Types in referenced assemblies". The following link should provide more information on the topic...

http://msdn.microsoft.com/en-us/library/vstudio/bb628653(v=vs.100).aspx

EDIT:

The following article could shed some more light on what you are seeing...

http://msdn.microsoft.com/en-us/library/bb907578(v=vs.110).aspx

In particular the following info...

When a service reference is added to a project, any types defined in the service are generated in the local project. In many cases, this creates duplicate types when a service uses common .NET Framework types or when types are defined in a shared library. To avoid this problem, types in referenced assemblies are shared by default. If you want to disable type sharing for one or more assemblies, you can do so in the Configure Service References dialog box. To disable type sharing in a single assembly In Solution Explorer, select the service reference. On the Project menu, click Configure Service Reference. In the Configure Service References dialog box, select Reuse types in specified referenced assemblies. Select the check box for each assembly in which you want to enable type sharing. To disable type sharing for an assembly, leave the check box cleared. To disable type sharing in all assemblies In Solution Explorer, select the service reference. On the Project menu, click Configure Service Reference. In the Configure Service References dialog box, clear the Reuse types in referenced assemblies check box.

Good Luck!

Upvotes: 0

Related Questions