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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:01:34+00:00 2026-06-15T00:01:34+00:00

I have wrote my public sealed class ObservableDictionary<TKey,TValue> : NotifyPropertyChangedClass, INotifyCollectionChanged, IDictionary<TKey, TValue> where

  • 0

I have wrote my public sealed class ObservableDictionary<TKey,TValue> : NotifyPropertyChangedClass, INotifyCollectionChanged, IDictionary<TKey, TValue> where TKey: IEquatable<TKey> class.

It marked as [Serializable].

But I got exception, when tried to serialize instance of ObservableDictionary<Int64, String>.

Exception message:

The MS.Internal.Data.EnumerableCollectionView type in assembly
“PresentationFramework, Version=4.0.0.0, Culture=neutral,” isn’t
marked with PublicKeyToken=31bf3856ad364e35 as serializable.

But I never used the MS.Internal.Data.EnumerableCollectionView type.

Where my mistake? My code below are located:

using System;
using System.ComponentModel;

namespace RememberEmployees {

    [Serializable]
    public abstract class NotifyPropertyChangedClass : INotifyPropertyChanged {        
        protected void NotifyPropertyChanged(string propertyName) {
            PropertyChangedEventHandler temp = PropertyChanged;
            if (temp != null) {
                temp(this, new PropertyChangedEventArgs(propertyName));
            }
        }        
        public event PropertyChangedEventHandler PropertyChanged;
    }
}

and

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.Specialized;

namespace RememberEmployees {   
    [Serializable]
    public sealed class ObservableDictionary<TKey,TValue> : NotifyPropertyChangedClass, 
        INotifyCollectionChanged, IDictionary<TKey, TValue> where TKey: IEquatable<TKey> {
        SortedDictionary<TKey, TValue> dict;

        IComparer<TKey> Comparer {
            get { return dict.Comparer; }
        }

        public ObservableDictionary() {
            dict = new SortedDictionary<TKey, TValue>();
            IsReadOnly = false;
        }

        private void NotifyCollectionChanged(NotifyCollectionChangedAction action) {
            NotifyCollectionChangedEventHandler temp = CollectionChanged;
            if (temp != null) {
                temp(this, new NotifyCollectionChangedEventArgs(action));
            }
        }

        private void NotifyCollectionChanged(NotifyCollectionChangedAction action, object item) {
            NotifyCollectionChangedEventHandler temp = CollectionChanged;
            if (temp != null) {
                temp(this, new NotifyCollectionChangedEventArgs(action, item));
            }
        }

        private void NotifyCollectionChanged(NotifyCollectionChangedAction action, int index) {
            NotifyCollectionChangedEventHandler temp = CollectionChanged;
            if (temp != null) {
                temp(this, new NotifyCollectionChangedEventArgs(action, index));
            }
        }

        private void NotifyCollectionChanged(NotifyCollectionChangedAction action, KeyValuePair<TKey, TValue> obj, int index) {
            NotifyCollectionChangedEventHandler temp = CollectionChanged;
            if (temp != null) {
                temp(this, new NotifyCollectionChangedEventArgs(action, obj, index));
            }
        }

        public event NotifyCollectionChangedEventHandler CollectionChanged;


        public void Add(TKey key, TValue value) {
            if (IsReadOnly)
                throw new Exception("Is Read Only");
            dict.Add(key, value);
            NotifyPropertyChanged("Count");
            NotifyCollectionChanged(NotifyCollectionChangedAction.Add, 
                dict.Cast<KeyValuePair<TKey, TValue>>().FirstOrDefault(n => n.Key.Equals(key)));
        }

        public bool ContainsKey(TKey key) {
            return dict.ContainsKey(key);
        }

        public ICollection<TKey> Keys {
            get { return dict.Keys; }
        }

        public bool Remove(TKey key) {
            if (IsReadOnly)
                throw new Exception("Is Read Only");
            if (!dict.Keys.Contains(key))
                return false;
            int x = 0;
            foreach (TKey item in dict.Keys) {
                if (item.Equals(key))
                    break;
                ++x;
            }
            KeyValuePair<TKey, TValue> val = dict.Cast<KeyValuePair<TKey, TValue>>().FirstOrDefault(n => n.Key.Equals(key));
            bool result = dict.Remove(key);
            if (result) {
                NotifyPropertyChanged("Count");
                NotifyCollectionChanged(NotifyCollectionChangedAction.Remove, val, x);
            }
            return result;
        }

        public bool Remove(KeyValuePair<TKey, TValue> item) {
            return Remove(item.Key);
        }

        public bool TryGetValue(TKey key, out TValue value) {
            return dict.TryGetValue(key, out value);
        }

        public ICollection<TValue> Values {
            get { return dict.Values; }
        }

        public TValue this[TKey key] {
            get {
                return dict[key];
            }
            set {
                dict[key] = value;
                NotifyCollectionChanged(NotifyCollectionChangedAction.Reset);
            }
        }

        public void Add(KeyValuePair<TKey, TValue> item) {
            Add(item.Key, item.Value);
        }

        public void Clear() {
            if (IsReadOnly)
                throw new Exception("Is Read Only");
            dict.Clear();
            NotifyCollectionChanged(NotifyCollectionChangedAction.Reset);
        }

        public bool Contains(KeyValuePair<TKey, TValue> item) {
            return dict.Contains(item);
        }

        public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) {
            if (arrayIndex > dict.Count)
                throw new IndexOutOfRangeException();
            int max = dict.Count - arrayIndex <= array.Count() ? dict.Count - arrayIndex : array.Count();
            for (int i = 0; i < max; i++) {
                array[i] = dict.Skip(arrayIndex).ToArray()[i];
            }
        }

        public int Count {
            get { return dict.Count; }
        }
        bool readOnly;

        public bool IsReadOnly {
            get { return readOnly; }
            set { readOnly = value; NotifyPropertyChanged("IsReadOnly"); }
        }

        public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() {
            return dict.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
            return dict.GetEnumerator();
        }
    }
}
  • 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-15T00:01:35+00:00Added an answer on June 15, 2026 at 12:01 am

    This has less to do with your class but with the data you did store in your collection. It seems that in your collection you have stored a ViewObject which internally does contain an EnumerableCollectionView object.

    When you serialize data you must be sure what parts of your object graph you do want to serialize. Just putting objects in your collection could cause half of you application data sent over the wire or to disc. There is a good reason why DataContractSerializer was invented.

    You should know before the serialize call what data you are going to serialize. Otherwise it could happen that e.g. in a client server application you are trying to deserialize types which are located in assemblies that do exist only on the server.

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

Sidebar

Related Questions

Okay, so i have this code i wrote: class Connection { public static StreamWriter
I have wrote below code. import java.io.*; class Test { public static void main(String
Let's say you have yourself a class like the following: public sealed class StringToInt
i have wrote the following polymorphic code: public abstract class A { readonly int
To get fully qualified path of application I have wrote a function: public class
I have wrote my websocket server class and wrote ServerPiplineFactory class but I don't
I have wrote a method to convert any layout Liner,Relative,Frame etc into Bitmap but
I have wrote a custom MultipleChoiceField. I have everything working ok but when I
i have wrote a script to produce an array of data but now want
I have the following test class that represents a composite _id: private sealed class

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.