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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:16:32+00:00 2026-06-04T08:16:32+00:00

I want to have this class serialized, so i can send it as the

  • 0

I want to have this class serialized, so i can send it as the body of a httpresponsemessage:

  [DataContract]
public class Subscription : TableServiceEntity
{
    [DataMember]
    public string SubscriptionId { get; set; }
    [DataMember]
    public bool IsAdmin { get; set; }
}

The way i want to use it:

 IList<Subscription> subs = ... ;

        return new HttpResponseMessage<IList<Subscription>>(subs);

It compiles, but when i run this part i get an error saying the IList can’t be serialized and i have to add it to the known type collection.
I’m guessing the members of TableServiceEntity are not serializable and that’s why i can’t serialize the whole list in all, but i don’t know how to resolve this issue.

Any ideas?

Sincerely,

Zoli

MODIFICATION

I added a new class just as it was said in the first comment and it looks like this:

 [DataServiceEntity]
[DataContract]
[KnownType(typeof(Subscription))]
public abstract class SerializableTableServiceEntity
{
    [DataMember]
    public string PartitionKey { get; set; }

    [DataMember]
    public string RowKey { get; set; }

    [DataMember]
    public DateTime Timestamp { get; set; }
}


[DataContract]
public class Subscription : SerializableTableServiceEntity
{
    [DataMember]
    public string SubscriptionId { get; set; }
    [DataMember]
    public bool IsAdmin { get; set; }
}

I still get the error saying to

add type to known type collection and to use the serviceknowntypeattribute before the operations

the only operation i use is this:

public class DBModelServiceContext : TableServiceContext
{
    public DBModelServiceContext(string baseAddress, StorageCredentials credentials)
        : base(baseAddress, credentials) {  }

    public IList<Subscription> Subscriptions
    {
        get
        {
            return this.CreateQuery<Subscription>("Subscriptions").ToArray();
        }
    }
}

MODIFICATION 2

MY interface looks like this:

  [OperationContract]
    [ServiceKnownType(typeof(IList<Subscription>))] 
    [WebGet(UriTemplate = "subscription/{value}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
    HttpResponseMessage<IList<Subscription>> GetSubscription(string value);

the implementation behind is:

 public HttpResponseMessage<IList<Subscription>> GetSubscription(string value)
    {                        
        var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
        var context = new DBModelServiceContext(account.TableEndpoint.ToString(), account.Credentials);
        IList<Subscription> subs = context.Subscriptions;

        return new HttpResponseMessage<IList<Subscription>>(subs);}
  • 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-04T08:16:34+00:00Added an answer on June 4, 2026 at 8:16 am

    I’ve managed to find the solution:

    The selfmade class( in my case: Subscription) has to be inherited from a custom TableServiceEntity class, which has datacontract, datamember and knowntype attributes:

    [DataContract]    
    [KnownType(typeof(Subscription))]
    public abstract class SerializableTableServiceEntity
    {
        [DataMember]
        public string PartitionKey { get; set; }
    
        [DataMember]
        public string RowKey { get; set; }
    
        [DataMember]
        public DateTime Timestamp { get; set; }
    }
    
     [DataContract]
        public class Subscription : SerializableTableServiceEntity
        {
            [DataMember]
            public string SubscriptionId { get; set; }
            [DataMember]
            public bool IsAdmin { get; set; }
        }
    

    And the key is that: You don’t send the result back as an HttpResponseMessage
    It will always be an HttpResponseMessage no matter what your return type is. If your return type is an IList, then it will be serialized and will be put in the response’s body automatically. So just send it back the way it is. If you want to modify the statuscode of the reply, you can get it done like this:

    WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
    

    You can get/set everything from the request/reponse body/header from

    WebOperationContext.Current

    I hope it helps!

    Addition:

    But be aware, that if you get your selfmadeclass(in my case subscription) type of object from the azure database, you won’t be able to delete it:

    Subscription s = (from e in this.CreateQuery<Subscription>("Subscriptions")
                                           where e.SubscriptionId == subscriptionID
                                           select e).FirstOrDefault();
    context.DeleteObject(s); //THIS WILL THROW AN EXCEPTION
    

    instead the return type has to something that is inherited from the TableServiceEntity, and you can only delete that.

    Please, if I’m wrong, update this post!

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

Sidebar

Related Questions

I have a class, which can be serialized using binary formatter. I want to
I have this class which I want to pass around Windows as LPARAM parameter.
I want to have immutable Java objects like this (strongly simplified): class Immutable {
I have subclassed a UITableViewCell and within this class I want to get it's
I have an issue regarding Sendkeys Class, as i want to use this class
I have an AS3 class with some getVideo function. I want to use this
I have List of particular class. I want to save this List at a
I have this string: comment_1234 I want to extract the 1234 from the string.
Let's suppose I have this object: [Serializable] public class MyClass { public int Age
Suppose I have this class: type Pet (name:string) as this = let mutable age

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.