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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:41:54+00:00 2026-06-02T07:41:54+00:00

I needed to serialize KeyValuePair and I found the solution here: Is there a

  • 0

I needed to serialize KeyValuePair and I found the solution here:

Is there a serializable generic Key/Value pair class in .NET?

So I used the accepted answer for that question which said all you need is to define class/struct like this

public class KeyValuePair<K,V>
{
  public K Key {get;set;}
  public V Value {get;set;}
}

This works but now there are 2 generic classes with same name. The custom class above and the one from System.Collections.Generics namespace.

So how does the compiler know which one to use when there is a code like this

myList=new List<KeyValuePair<string, string>>();

One has signature KeyValuePair<K,V> and the other is KeyValuePair<TKey,TValue>, so both have same number of Type Parameters.

Why does the code compile with no errors?

  • 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-02T07:41:57+00:00Added an answer on June 2, 2026 at 7:41 am

    Name, namespace an generic type parameters are unique per assembly. Nothing prevents you from creating another type like you do it, but the compiler will not be able to figure out which one to use if yet another project uses both assemblies (the system one and yours).

    Another variant of the same problem occurs when two same assemblies with different versions are in use, the compiler will pick and bind to one which can cause painful a debugging experience (it looks as if the types shoud match but they don’t – the framework itself has no problem with it though).

    Note that you cannot replace a type in another assembly by “redefining” is like this.

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

Sidebar

Related Questions

I wanted to serialize a java class to XML with XStream. I needed to
I needed a generic collection or list that can fire an event when an
I have a settings class that I want to be able to serialize and
I have a class which i am serializing. I annotated it with [Serializable] and
I recently needed to serialize a datatable to JSON. Where I'm at we're still
We maintain a large number of .NET Project and Solution files by hand; it's
A base project contains an abstract base class Foo. In separate client projects, there
I have a form with the following button: <input id=test2 class=formbutton type=submit value=Play again
I've been working on a rails project where I am needed to serialize permissions
I have a MarshalByRefObject which I needed to serialize and store (in a database),

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.