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

  • Home
  • SEARCH
  • 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 3606894
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:18:25+00:00 2026-05-18T21:18:25+00:00

I have an interface IServiceInfo and an abstract class ServiceInfo. There are several classes

  • 0

I have an interface IServiceInfo and an abstract class ServiceInfo. There are several classes inherited from ServiceInfo, like CoreServiceInfo, ModuleServiceInfo etc. There is a service contract named RootService which returns IServiceInfo.

 public IServiceInfo GetServiceInfo()
 {
     return (IServiceInfo)new CoreServiceInfo();
 }

I am having problem serializing. I can use ServiceKnownType to identify base class, and KnownType to identify child class.

Problem is I do not know all the ServiceInfo child, since application can have plugins with different child inherited from ServiceInfo, so I cannot tell serializer to have all the child in serialized XML.

I can ignore abstract class, but it contains certain common implementation so I need to keep it. As a work around I can have another class say “sampleServiceInfo” and convert all the info classes to sampleServiceInfo and return it from Service method, and define KnownType to ServiceInfo class.

[KnownType(typeof(sampleServiceInfo))]
public class ServiceInfo : IServiceInfo

But that does not sound pretty way to do it. Please suggest. Do I need to write custom serializer? Is there any way to serialize base only and ignoring the child when both has same members?

  • 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-18T21:18:26+00:00Added an answer on May 18, 2026 at 9:18 pm

    Get all the types in all loaded assemblies that implement given abstract class or interface(ref:Implementations of interface through Reflection)

     var allTypes =  AppDomain
                .CurrentDomain
                .GetAssemblies()
                .SelectMany(assembly => assembly.GetTypes())
                .Where(type => typeof(A).IsAssignableFrom(type));
    

    Then create serializer passing allTypes as known types parameter, as below

    var serializer = new DataContractSerializer(typeof(A), allTypes);
    

    that’s it – you will be able to serialize and deserialize any type that derives from A (A could be class or interface, if interface, serializer writes elements as deriving from xs:anyType.

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

Sidebar

Related Questions

If I have interface IFoo, and have several classes that implement it, what is
I have interface IModule and several classes that implements it. In test i need
Suppose we have: interface Foo { bool Func(int x); } class Bar: Foo {
Have a interface class abc { public: virtual int foo() = 0; ... }
I have interface in service layer with several methods starting with Get and FxCop's
i have interface: public interface Inx<T> { T Set(Data data); } simple class with
Lets say you have interface definition. That interface can be Operation . Then you
I have an Interface called IStep that can do some computation (See Execution in
I have an interface that I have defined in C++ which now needs to
I have an interface - here's a nicely contrived version as an example: public

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.