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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:08:12+00:00 2026-05-28T05:08:12+00:00

i am trying to serialize a field of my class. Withou it serialization is

  • 0

i am trying to serialize a field of my class. Withou it serialization is fine, with it a get SerializationException.

Field is : private readonly ObservableCollection<CellVM> Values;
Exception is

Type System.ComponentModel.PropertyChangedEventManager in assembly WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 is not marked as serializable.

I am targeting Framework 3.5.

I found some suggestions, that it could be problem with serialization of observalble collections, but that should be fixed by 3.5 sp1.

Have no idea how to fix that, any ideas? thank you.

CellVM class:

[Serializable]
public class CellVM:ANotifyPropertyChanged
{
    public Cell model;

    public int X
    {
        get { return model.X; }
        set { model.X = value; OnPropertyChanged("X"); }
    }

    public int Y
    {
        get { return model.Y; }
        set { model.Y = value; OnPropertyChanged("Y"); }
    }

    public string Value
    {
        get
        {
            return  model.ActualValue;
        }
        set { model.ActualValue = value; OnPropertyChanged("Value"); }
    }

    [NonSerialized]
    private bool _isActive;
    public bool IsActive
    {
        get
        {
            return _isActive;
        }
        set
        {
            _isActive = value;
            OnPropertyChanged("IsActive");
            OnPropertyChanged("BackgroundBrush");
            OnPropertyChanged("HighlightBrush");
        }
    }

    public bool IsReadOnly
    {
        get
        {
            if(model.InitialValue.Equals(model.RightValue))
            {
                return true;
            }
            return false;
        }
    }

    public bool IsHighLighted
    {
        get;
        set;
    }

    private bool _isInvalid;
    public bool IsInvalid
    {
        get { return _isInvalid; }
        set
        {
            _isInvalid = value;
            OnPropertyChanged("IsInvalid");
            OnPropertyChanged("BackgroundBrush");
        }
    }

    private bool _isValueMode;
    public bool IsValueMode
    {
        get
        {
            return _isValueMode;
        }
        set
        {
            _isValueMode = value;

            OnPropertyChanged("IsValueMode");
            OnPropertyChanged("ValueVisibility");
            OnPropertyChanged("PossibilityVisibility");
        }
    }

    [NonSerialized]
    private FontWeight _valueFontWeight;
    public FontWeight ValueFontWeight
    {
        get
        {
            return _valueFontWeight;
        }
        set { _valueFontWeight = value; OnPropertyChanged("ValueFontWeight");}
    }

    [NonSerialized]
    private Brush _valueColor;
    public Brush ValueColor
    {
        get
        {
            if(_valueColor == null)
            {
                return new SolidColorBrush(Colors.Black);
            }
            return _valueColor;
        }
        set { _valueColor = value; OnPropertyChanged("ValueColor"); }
    }

    public Visibility ValueVisibility
    {
        get
        {
            if(IsValueMode)
            {
                return Visibility.Visible;
            }
            return Visibility.Hidden;
        }
    }

    public Visibility PossibilityVisibility
    {
        get
        {
            if (!IsValueMode)
            {
                return Visibility.Visible;
            }
            return Visibility.Hidden;
        }
    }

    private bool _isCheckInvalid;
    public bool IsCheckInvalid
    {
        get
        {
            return _isCheckInvalid;
        }
        set
        {
            _isCheckInvalid = value;
            OnPropertyChanged("IsCheckInvalid");
            OnPropertyChanged("HighlightBrush");
        }
    }

    public Brush HighlightBrush
    {
        get
        {
            if(IsActive && IsReadOnly)
            {
                return ColorManager.CellActive;
            }

            if (IsCheckInvalid)
            {
                ColorAnimation animation = new ColorAnimation
                {
                    From = Colors.Firebrick,
                    To = Colors.WhiteSmoke,
                    Duration = new Duration(TimeSpan.FromSeconds(1)),
                    AutoReverse = true
                };
                SolidColorBrush brush = new SolidColorBrush(Colors.Firebrick);
                animation.RepeatBehavior = RepeatBehavior.Forever;
                animation.AccelerationRatio = 0.5;

                brush.BeginAnimation(SolidColorBrush.ColorProperty, animation);

                return brush;
            }

            return new SolidColorBrush(Colors.Transparent);
        }
    }

    public Brush BackgroundBrush
    {
        get
        {

            if (IsActive)
            {
                if (!IsReadOnly)
                {
                    return ColorManager.CellActive;
                }
            }
            if (IsInvalid)
            {
                return ColorManager.CellInvalid;
            }
            if (IsHighLighted)
            {
                return ColorManager.CellHighlighted;
            }

            return new SolidColorBrush(Colors.White);
        }
    }

    [NonSerialized]
    private Brush _backgroundAnimationBrush;
    public Brush BackgroundAnimationBrush
    {
        get { return _backgroundAnimationBrush; }
        set { _backgroundAnimationBrush = value;                OnPropertyChanged("BackgroundAnimationBrush"); }
    }

    public Brush PossibilitiesBrush
    {
        get
        {
            return new SolidColorBrush(PossibilitiesColor);
        }
    }

    private Colour _possibilitiesColor;
    public Colour PossibilitiesColor
    {
        get
        {
            if (_possibilitiesColor == null)
            {
                return new Colour(Colors.Black);
            }
            return _possibilitiesColor;
        }
        set
        {
            _possibilitiesColor = value;
            OnPropertyChanged("PossibilitiesColor");
            OnPropertyChanged("PossibilitiesBrush");
        }
    }

    public ObservableCollection<string> Possibilities
    {
        get { return model.Possibilities; }
        set 
        { 
            model.Possibilities = value; 
            OnPropertyChanged("Possibilities");
            OnPropertyChanged("PossibilityVisibility"); 
        }
    }

    private string _toolTip;
    public string ToolTip
    {
        get { return _toolTip; }
        set { _toolTip = value; OnPropertyChanged("ToolTip"); }
    }

    public CellVM(Cell model,bool isHighlighted)
    {
        this.model = model;
        IsValueMode = true;
        IsHighLighted = isHighlighted;
    }

    public void signalError(string message)
    {
        ToolTip = message;
        IsInvalid = true;
    }

    public void resetError()
    {
        if(IsCheckInvalid)
        {
            return;
        }
        ToolTip = null;
        IsInvalid = false;
    }


    public void AnimateError()
    {
        ColorAnimation animation = new ColorAnimation
        {
            From = Colors.Firebrick,
            To = Colors.Transparent,
            Duration = new Duration(TimeSpan.FromSeconds(1.5)),
            AutoReverse = false
        };
        animation.Completed += new EventHandler(animation_Completed);
        SolidColorBrush brush = new SolidColorBrush(Colors.Transparent);
        animation.AccelerationRatio = 0.5;

        BackgroundAnimationBrush = brush;
        brush.BeginAnimation(SolidColorBrush.ColorProperty, animation);
    }

    public void AnimateHint()
    {
        ColorAnimation animation = new ColorAnimation
        {
            From = Colors.DarkGreen,
            To = Colors.Transparent,
            Duration = new Duration(TimeSpan.FromSeconds(1.5)),
            AutoReverse = false
        };
        animation.Completed += new EventHandler(animation_Completed);
        SolidColorBrush brush = new SolidColorBrush(Colors.Transparent);
        animation.AccelerationRatio = 0.5;

        BackgroundAnimationBrush = brush;
        brush.BeginAnimation(SolidColorBrush.ColorProperty, animation);

    }

    private void animation_Completed(object sender, EventArgs e)
    {
        BackgroundAnimationBrush = null;
    }
}

CellVM SuperClass (ancestor):

[Serializable]
public abstract class ANotifyPropertyChanged : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = this.PropertyChanged;
        if (handler != null)
        {
            var e = new PropertyChangedEventArgs(propertyName);
            handler(this, e);
        }
    }
}
  • 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-28T05:08:13+00:00Added an answer on May 28, 2026 at 5:08 am

    Try out marking event PropertyChanged by [NonSerialized] attribute

    below is syntax for events: (see MSDN)

    [field:NonSerializedAttribute()] 
    public event ChangedEventHandler Changed;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to serialize object having the following field: private TreeSet<TimeSlot<T>> counterTimeSlotSet =
I am trying to serialize a large (~10**6 rows, each with ~20 values) list,
I'm trying to serialize a class derived from List<> using DataContract. The problem is
I'm trying to build a Lucene Serializer class that would serialize/de-serialize objects (classes) with
I am trying to use MOXy JAXB to serialize a class A which looks
Trying to serialize a union-like data-type. There is an enum field indicating the type
I'm trying to serialize an array of 7000 POJO using GSON and the serialization
I have been trying to serialize a list that contains arrays and lists. I
I am trying to serialize a PagedList object ( https://github.com/martijnboland/MvcPaging/blob/master/src/MvcPaging/PagedList.cs ) to Json, like
I'm trying to serialize an object to XML that has a number of properties,

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.