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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:30:51+00:00 2026-05-31T04:30:51+00:00

I am working on providing a generic JSON serialiation/deserialization service as a WCF service.

  • 0

I am working on providing a generic JSON serialiation/deserialization service as a WCF service.

in order to do this, I have the following DataContract

[DataContract]
public class SerializationRequest
{
     [DataMember]
     public Object Data {get;set;}     //Object to be serialized

     [DataMember]
     public string Type {get;set;}       //Type of the Data object

}

The problem I am experiencing is I am getting the following error:

The InnerException message was ‘Type ‘System.RuntimeType’ with data contract name ‘RuntimeType:http://schemas.datacontract.org/2004/07/System’ 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.’. Please see InnerException for more details.

Which tells me I either need to make the DataContractJSONSerializer aware of the type, or that Type is unable to be serialized.

I have tried registering the type of object and adding it to the Serializers “Known Types”, but this doesn’t seem to work, which makes me believe that my problem lies in having a parameter of type Type on my DataContract.

How can I accomplish this? I need to be able to call the following code(“ish”).

        DataContractJsonSerializer serializer = new DataContractJsonSerializer(request.Type);
        MemoryStream ms = new MemoryStream();
        serializer.WriteObject(ms, request.Data);
        string json = Encoding.Default.GetString(ms.ToArray());
        ms.Dispose();

        return new JSONSerializationResponse() {Data = json};

EDIT

I have changed the type parameter to be the Full Qualified Name of the type that is to be serialized, but I am still getting the same problem when I call the following code in my Remote WCF Service:

        Type type = Type.GetType(request.Type);
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(type, new Type[]{Type.GetType(request.Type)});
        MemoryStream ms = new MemoryStream();
        serializer.WriteObject(ms, request.Data);
        string json = Encoding.Default.GetString(ms.ToArray());
        ms.Dispose();

        return new JSONSerializationResponse() {Data = json};

I have tried adding that created type to the KnownTypes in the Constructor of the DataContractJSONSerializer, but that is not working either…any ideas?

Here is an example of a simple class that would be called that needs to be able to be serialized

[DataContract]
[KnownType(typeof(Person))]
public class Person
{
    [DataMember]
    public string Age {get;set;}

    [DataMember]
    public strign Name {get;set;}
}

so now I should be able to pass this into my request object with specifying the type name, and then get back a JSON Result of this object.

  • 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-31T04:30:52+00:00Added an answer on May 31, 2026 at 4:30 am

    I’m not sure why you need the .NET type in JSON, but you can serialise the Type to a string and then obviously create a Type from a string.

    You can use the Type.FullName and Assembly.GetType(“My.Type”) to get the string (serialise) and create Type from the name (deserialise).

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

Sidebar

Related Questions

Working with Linq2Sql as a driver for a Wcf Service. Lets go bottom up....
I am working on providing PhoneGap functionality in a UIWebView in MonoTouch. I have
Im working in a project providing rest services on the azure pllatform. The service
I have a working coffeescript/backbone idiom that looks like this: SidebarWidgets = ((() ->
I've been struggling with this problem for 5 hours and I have a feeling
I am trying to write a generic one-size-fits-most repository pattern template class for an
I'm working on pseudo-transport layer software that runs over UDP, providing reliable connection-oriented transmission,
When working with lots of classes in a node module is the following mechanism
I have rewritten the Binary Search Tree code found in the following links to
I am working on a little site, providing high quality photography by three photographers.

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.