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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:29:23+00:00 2026-06-12T15:29:23+00:00

Possible Duplicate: C# WCF: When is it appropriate to use the KnownType attribute? Not

  • 0

Possible Duplicate:
C# WCF: When is it appropriate to use the KnownType attribute?

Not long ago, we needed in class to create, as part of a project, a C# web client. The teacher instructed us to put the attribute DataContract above each class that will be passed.

Then the teacher told us that if you have some thing like this:

               A
              / \
             /   \
            B     C

you need to write class A in the following way:

[DataContract]
[KnownType(typeof(B))]
[KnownType(typeof(C))]
public class A
{
}

Isn’t this completly against the idea of polymorphism? why should a class know who inherits the class?

  • 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-06-12T15:29:24+00:00Added an answer on June 12, 2026 at 3:29 pm

    This doesn’t really have anything to do with C# and polymorphism; rather with serialization. The WCF infrastructure needs to be able to take something like a byte array off the wire and create an object out of it. If class A is an abstract type, there is no way that object can be instantiated. The framework needs to know what types it might receive over the wire so it can inspect the metadata and instantiate the right type of object.

    Put another way, the attributes don’t tell the class anything about its inheritors (indeed, the list need not include all inheritors); this is strictly so the framework will know what types it can expect to be asked to construct.

    I would add, though, that adding the DataContract and DataMember attributes is not always required. They are available for scenarios where you may want to have more fine grained control, such as excluding a public property from serialization. Usually if the type is serializable it can be passed without the attributes.

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

Sidebar

Related Questions

Possible Duplicate: How to use a WSDL file to create a WCF service (not
Possible Duplicate: How do i specify wcf behaviorExtension class type without the assembly version
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: How can WCF consuming data from database phpmyadmin? I want to ask
Possible Duplicate: Web Service vs WCF Service Duplicate: Web Service vs WCF Service What
Possible Duplicate: Ambiguous reference in WCF and client application I am using few classes
Possible Duplicate: difference between WCF Services and Web Services and REST Service I have
Possible Duplicate: Adding methods to DataContract objects for WCF is possible to expose method
Possible Duplicate: Combining jQuery :not and :nth-child selectors is this possible? Here is my

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.