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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:13:07+00:00 2026-06-07T08:13:07+00:00

I’m tinkering around with WCF and MemoryCache. The goal is to host WCF in

  • 0

I’m tinkering around with WCF and MemoryCache. The goal is to host WCF in a Windows Service so different clients can access this cache.

The first part, setting up the host works fine and I’m able to write to and read from the cache via a separate client application. At least, when trying to put very simple objects in the cache, like a string or a value type like int.

When I try a ‘custom’ object, even if it only has a string property, stuff starts to go wrong:

There was an error while trying to serialize parameter http://tempuri.org/:value. 

TheInnerException message was 'Type 'Solution.MyType' with data contract name 
'MyType:http://schemas.datacontract.org/2004/07/MyType' 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.

Now after some searching I found that I might had to decorate my type with a KnownType attribute, but alas, with no succes. I also tried decorating it with DataContract and DataMember attributes, but no sigar either.

What to do now? Isn’t the WCF DataContractResolver supposed to do this work for me? I find it hard to believe I’d have to write a custom DataContractResolver for every class I want to have serialized. What else are the DataContract and DataMember attributes for?

What am I missing here? Note also that MyType does not inherit from another class (save 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-06-07T08:13:09+00:00Added an answer on June 7, 2026 at 8:13 am

    I’ve solved this by implementing some custom serialisation:

    string result = string.Empty;
            Encoding encoding = Encoding.UTF8;
            DataContractSerializer ser = new DataContractSerializer(typeof(MyType));
            MemoryStream stream = new MemoryStream();
            using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream, encoding, true))
            {
                ser.WriteObject(writer, principal);
                writer.Flush();
                result = encoding.GetString(stream.ToArray());
            }
    

    which suffices for my purposes.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

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.