Click to Rate and Give Feedback
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ContractNamespaceAttribute Class

Updated: November 2007

Specifies the CLR namespace and XML namespace of the data contract.

Namespace:  System.Runtime.Serialization
Assembly:  System.Runtime.Serialization (in System.Runtime.Serialization.dll)

Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Module, Inherited := False,  _
    AllowMultiple := True)> _
Public NotInheritable Class ContractNamespaceAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As ContractNamespaceAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Module, Inherited = false, 
    AllowMultiple = true)]
public sealed class ContractNamespaceAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Module, Inherited = false, 
    AllowMultiple = true)]
public ref class ContractNamespaceAttribute sealed : public Attribute
J#
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Module, Inherited = false, AllowMultiple = true) */
public final class ContractNamespaceAttribute extends Attribute
JScript
public final class ContractNamespaceAttribute extends Attribute

Apply the ContractNamespaceAttribute attribute to an assembly that contains types to which the DataContractAttribute has been applied. The ContractNamespaceAttribute enables you to set a namespace that is different than the one generated when the type is serialized. For more information about how names are generated, see Data Contract Names.

If you are using a type to conform to an existing data contract, you must match the namespace of the existing contract by using the ContractNamespaceAttribute (or the Namespace property of the DataContractAttribute class).

Note:

In any code, you can use the word ContractNamespace instead of the longer ContractNamespaceAttribute.

The following example shows the ContractNamespaceAttribute applied to an assembly.

Visual Basic
<assembly: ContractNamespaceAttribute("http://www.cohowinery.com/employees", _
   ClrNamespace := "Microsoft.Contracts.Examples")>

Namespace Microsoft.Contracts.Examples
    <DataContract()>  _
    Public Class Person
        <DataMember()>  _
        Friend FirstName As String
        <DataMember()>  _
        Friend LastName As String
    End Class 
End Namespace 

C#
[assembly: ContractNamespaceAttribute("http://www.cohowinery.com/employees",
    ClrNamespace = "Microsoft.Contracts.Examples")]
namespace Microsoft.Contracts.Examples
{
    [DataContract]
    public class Person
    {
        [DataMember]
        internal string FirstName;
        [DataMember]
        internal string LastName;
    }
}

System..::.Object
  System..::.Attribute
    System.Runtime.Serialization..::.ContractNamespaceAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows Vista, Windows XP SP2, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker