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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:54:30+00:00 2026-05-26T19:54:30+00:00

Suppose we start from scratch in Visual Studio 2010 and add a ‘WCF Service

  • 0

Suppose we start from scratch in Visual Studio 2010 and add a ‘WCF Service Aplication’. We add this method and implementation:

// (in IService1.cs)
    [OperationContract]
    Dictionary<string, string> GetDictionary();

// (in Service1.svc.cs)
    public Dictionary<string, string> GetDictionary()
    {
        return new Dictionary<string, string>(
            StringComparer.InvariantCultureIgnoreCase);
    }

Then we add a new ‘Console Application’ to the same solution, add a Service Reference to our service project (using all the default settings), and add this code to Main:

        var c = new ServiceReference1.Service1Client();

        var d = c.GetDictionary();

        d.Add("key",string.Empty);
        // Since this *should* be a case-insensitive dictionary,
        // this add *should* fail
        d.Add("KEY", string.Empty);

        Console.WriteLine("Both Add()s succeeded :(");
        Console.ReadKey();

We expect this code to fall over, because a case-insensitive dictionary would regard key and KEY as the same key, and so would throw on the second Add.

Unfortunately, when everything is compiled and run, we get a sad face :(, because when the Dictionary comes across the WCF layer it ‘forgets’ that it was made with a specific, non-default, Comparer, and instead acquires strings default equality comparer.

Is there an easy setting to change so that the Comparer property of the Dictionary will be preserved as it goes across the wire? Or must I create a custom class?

(I’ve seen XML serialization of a Dictionary with a custom IEqualityComparer but it didn’t offer me much enlightenment. I’ve also seen this codeproject comment from 3 years ago, but it is my question, not an answer)

  • 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-26T19:54:31+00:00Added an answer on May 26, 2026 at 7:54 pm

    If you use the standard mechanism like “Add Service Reference” etc., WCF by design will create a completely separate copy of your data structures based on the structure on the wire, e.g. the XML-serialized structure that can be expressed in XML schema (XSD).

    This does not include anything that’s more behavior (code) rather than actual data – things like comparers etc.

    There is no setting to “turn” this on – it just cannot be done. The only way to solve this – when you control both ends of the communication wire, and both are .NET platforms – is to share that common stuff both sides need (service contracts, data contracts etc.) in a separate assembly that both the server as well as the client reference. On the client, you need to make sure to add the reference to that shared assembly before creating the WCF proxy – in that case, the WCF runtime will reuse the existing data structures (like your dictionary with a custom comparer) from the shared assembly, instead of creating new, boiler-plate copies.

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

Sidebar

Related Questions

Suppose code like this: class Base: def start(self): pass def stop(self) pass class A(Base):
Suppose we start from the default new WPF project with App.xaml/cs , MainWindow.xaml/cs .
Suppose There are some activity. I want to start another activity from the main
Suppose your git history looks like this: 1 2 3 4 5 1–5 are
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
I'm running a process from inside a windows service using: ProcessStartInfo processStartInfo = new
Suppose I have the following Event model: from django.db import models import datetime class
Suppose there is a exe or process which finds process id of newly start
I would like to develop a Forum from scratch, with special needs and customization.
Will replacing a rejected iPhone binary cause a new review process to start from

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.