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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:06:10+00:00 2026-06-09T20:06:10+00:00

Background: We are using an attribute that changes the output of the response to

  • 0

Background: We are using an attribute that changes the output of the response to a JSON object when certain headers are passed. Another attribute returns XML when the appropriate accept header is passed. If the accept header is missing or “html”, a test page is returned.

I need to be able to serialize an object structure like this:

[DataContract]
public class ResponseModel
{
   [DataMember]
   public bool Success { get; set;}

   [DataMember]
   public dynamic Data { get; set; } //I have tried "Object" as well

   [DataMember]
   public ApiErrorModel Error { get; set; } 

}

//for reference
[DataContract]
public class ApiErrorModel 
{
    [DataMember]
    public string ErrorCode { get; set; }

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

The problem I’m having is while I haven’t been able to test any error states yet, when it goes to serialize a structure like this:

[DataContract]
public class DatabaseModel
{
   [DataMember]
   List<Database> Database { get; set; }
   //snip implementation
}

[DataContract]
public class Database
{
   [DataMember]
   [Required]
   public string DatabaseName { get; set; }

   [DataMember]
   List<Guid> APITokens { get; set; }

   //snip other fields..., Guids and strings...
}

It fails, giving me the error:

Type ‘[namespace].Api.Business.Web.Models.DatabaseModel’ with data contract name ‘DatabaseModel:http://schemas.datacontract.org/2004/07/%5Bnamespace%5D.Api.Business.Web.Models&#8217; is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

I have researched using a DataContractResolver, but I can’t seem to get it to work with the JSON version of it. It may be easier to switch to JSON.NET or JavaScriptSerializer serializer, but it needs to work for XML as well (This might be a JSON-specific issue). I’m wondering if there’s a way to fix this without adding every type of list I’m going to use to the serialization method list of known types.

  • 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-09T20:06:11+00:00Added an answer on June 9, 2026 at 8:06 pm

    JSON.NET is basically the way to go. It seems the DataContractJsonSerializer isn’t up for the task.

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

Sidebar

Related Questions

Background Using JavaScript, I need to sort a large JSON object based on a
Background: Using jQuery 1.7 client side PHP server side Using json responses with json_encode
How to make android icons with transparent background using eclipse.I know that we can
I'm doing background subtraction using opencv. The problem is the foreground object is not
I am trying to write a function that will take an xml object, an
Background: I'm using MEF to help compose an Excel 2007 Add-In (VSTO) that can
Background: Using unix, codeigniter from localhost. I'd like to run a controllers via a
Background Using boost and other similar libraries is the easiest way to find compiler
I'm trying to set an image as the background using this code: root.setStyle(-fx-background-image: url('splash.jpg');
I'm trying to create a new spinner background using a 9 patch picture. I've

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.