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 6078821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:52:35+00:00 2026-05-23T10:52:35+00:00

Basically as the title says: [DataContract(Name = {0}Item)] //This will format properly public class

  • 0

Basically as the title says:

[DataContract(Name = "{0}Item")] //This will format properly
public class GenericItem<T>
{
    [DataMember(Name = "The{0}")] //This will NOT format properly
    public T TheItem { get; set; }
}

[CollectionDataContract(Name = "{0}Items")] //This will format properly
public SpecialCollection<T> : Collection<T> { }

[ServiceContract(Name = "{0}Service")] //This will NOT format properly
public interface IGenericService<T>
{
    [OperationContract(Name = "Get{0}")] //This will NOT format properly
    GenericItem<T> Get<T>();
}

So, there ya have it… what works and doesn’t work… but the question is… why? Obviously .NET is able to create a concrete type and format the name when using a DataContract and CollectionDataContract and stating the type (i.e. GenericItem<Foo> or SpecialCollection<Foo>. So why not have the DataMember also be able to format as well?

The ServiceContract/OperationContract I can sort of understand in the manner it’s left in above (sorta), but what I don’t understand is when you give it a concrete type the operations still won’t work properly:

[ServiceContract(Name = "FooService")]
public interface FooService : IGenericService<Foo> { }

public interface IGenericService<T>
{
    [OperationContract(Name = "Get{0}")] //This will NOT format properly
    T Get<T>();
}

Again, why? Obviously I’m declaring a concrete type of Foo here which means the IGenericService is an IGenericService<Foo> so shouldn’t the OperationContract name be formatted since it KNOWS the type?


Update:

I just remembered why I was upset about not being able to use a Generically formatted ServiceContract… when I have the implement the service I’m giving it a concrete type…

//See! I gave it a concrete type to go by!
[ServiceBehavior(...)]
public class MyService : IGenericService<Foo> { ... }

I created a Microsoft Connect request for this. Please upvote it if you want this feature for the other attributes. http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2327048-enable-generics-for-datamemberattribute-serviceco

  • 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-23T10:52:36+00:00Added an answer on May 23, 2026 at 10:52 am

    This seems to be an implementation choice by MS.
    In System.Runtime.Serialization.DataContract it builds up the name by doing:

    private static XmlQualifiedName GetDCTypeStableName(Type type, DataContractAttribute dataContractAttribute)
    {
      string localName;
      if (dataContractAttribute.IsNameSetExplicit)
      {
        string str = dataContractAttribute.Name;
        if (str == null || str.Length == 0)
        {
           ...
        }
        else
        {
          if (type.IsGenericType && !type.IsGenericTypeDefinition)
            str = DataContract.ExpandGenericParameters(str, type);
          localName = DataContract.EncodeLocalName(str);
        }
      }
    

    So it explicitly builds out the generic name.
    In the case of ServiceContract stuff, that is handled in System.ServiceModel.Description.TypeLoader and System.ServiceModel.Description.NamingHelper, and does not do anything with generic types (at last not that I am seeing).

    So I’m guessing since these contracts stem from different assemblies and namespaces, they may have been implemented by different teams to begin with.

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

Sidebar

Related Questions

I'm not really sure how to title this question but basically I have an
Like the title says, my code basically does this: set proxy, test proxy, do
The title basically says it all. I mainly want to do this so that
The title basically says it all. I'm aware this can't be done using traditional
Basically, the title says everything. The numbers are not too big (the maximum for
Basically what the title says. (Forgive me because I am a .NET newb) In
Basically what the title says... I need to have an image that when clicked,
Basically what the title says, I want to get the URL and HTTP Verb
Basically what the title says. I created a new MVC application. I'm trying to
Sorry for the confusing title, but it basically says it all. Here's the structures

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.