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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:33:25+00:00 2026-05-12T06:33:25+00:00

I have two classes SccmAction and TicketAction which both implement interface IDelivery. These classes

  • 0

I have two classes SccmAction and TicketAction which both implement interface IDelivery. These classes will be transmitted on a processing queue from which I just want to pull the message and act upon the Deliver method.

It seems however that I cannot deserialize to an interface because when I attempt to do so a System.NotSupportedException is thrown. From what I have gathered the XMLSerializer requires a concrete type for serialization. Does this leave me having to create an abstract class which implements IDelivery and inheriting SccmAction and ArsAction from it? Have I missed something that?

Edit Further Clarification

I may have a design flaw but my purpose is to pull messages off of a queue containing these objects. My intention was to have all objects coming off of this queue implement the interface ensuring that the application processing the objects just operates on the Deliver method. Each objects implementation of Deliver would vary.

Code to Deserialize

using (SqlConnection connection =
    new SqlConnection(ConnectionString))
{
    SqlCommand command = new SqlCommand(ReceiveString, connection);
    connection.Open();

    SqlDataReader reader = command.ExecuteReader();

    while (reader.Read())
    {
        byte[] sb = (byte[])reader["message_body"];
        SccmAction sa = DeserializeObject<SccmAction>(sb);
        IDelivery iD = DeserializeObject<IDelivery>(sb);
    }

    reader.Close();
}

public static T DeserializeObject<T>(byte[] ba)
{
    XmlSerializer xs = new XmlSerializer(typeof(T));
    MemoryStream memoryStream = new MemoryStream(ba);
    XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
    return (T)xs.Deserialize(memoryStream);
}

Classes and Interface

[Serializable]
public class SccmAction : IDelivery
{
    public string MachineName { get; set; }
    public string CollectionName { get; set; }
    public string Action { get; set; }
    public DateTime EntryDateTime { get; set; }

    public SccmAction () { }

    public void Deliver()
    {
        throw new NotImplementedException();
    }
}

[Serializable]
public class ArsAction : IDelivery
{
    public string MachineName { get; set; }
    public string CustomerName { get; set; }

    public ArsAction() { }

    public void Deliver()
    {
        throw new NotImplementedException();
    }
}

public interface IDelivery
{
    void Deliver();
}
  • 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-12T06:33:26+00:00Added an answer on May 12, 2026 at 6:33 am

    Simply put, you can’t serialize an interface without any dirtiness. But why do you want to serialize your interface anyway, it doesn’t hold any state. It only has a declaration for a method.

    You might want to create a Serialize method inside your classes. So they can serialize themselves individually, they know which type they are.

    Besides, how do you expect the XmlSerializer to Deserialize to an exact type without providing it? It can’t simply pick what to Deserialize to….

    You could however change this line

    IDelivery iD = DeserializeObject<IDelivery>(sb);
    

    to this

    IDelivery iD = DeserializeObject<SccmAction>(sb);
    

    If you dont know what type you are deserializing to initially (ArsAction or SccmAction), then you can do something like this.

    public static IDelivery DeserializeFromString(string xml)
    {
          //replace this stream with whatever you are useing
          StringReader strReader = new StringReader(xml);
          XmlReader reader = new XmlTextReader(fs); //important to use XmlReader
          reader.MoveToContent(); //move to root
    
          String className = reader.Name.Trim(); //read the class name 
    
          //use the namespace IDelivery is located in
          className  = "IDeliveryNamespace." + className;
    
          //get the type
          Type classType = Type.GetType(className);
    
          XmlSerializer serializer = new XmlSerializer(Type.GetType(className));      
    
          // Declare an object variable of the type to be deserialized.
          IDelivery i;
          // Use the Deserialize method to restore the object's state.
          i = (IDelivery)Convert.ChangeType(serializer.Deserialize(reader),classType);
          return i;
    }
    

    Of course this assumes that you your Serializable class Name is not changed. Meaning ArsAction class serializes to and as far as I can tell from what you posted that is the case.

    This code is a little dirty, but it should give you a starting point.

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

Sidebar

Ask A Question

Stats

  • Questions 164k
  • Answers 164k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In the threads you linked Raymond Hettinger pretty much sums… May 12, 2026 at 12:22 pm
  • Editorial Team
    Editorial Team added an answer I'm not sure you need to reach for ADPlus just… May 12, 2026 at 12:22 pm
  • Editorial Team
    Editorial Team added an answer Please see this question about geo-search in Lucene. I believe… May 12, 2026 at 12:22 pm

Related Questions

I have two classes, and want to include a static instance of one class
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have two classes that each need an instance of each other to function.
I have two classes: Media and Container. I have two lists List<Media> and List<Container>
I have two classes A and B in two different .NET assemblies: AssemblyA and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.