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

  • Home
  • SEARCH
  • 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 6728741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:12:23+00:00 2026-05-26T10:12:23+00:00

I have a class I serialize to a file, ie. myfile01.myfile. I’m using binary

  • 0

I have a class I serialize to a file, ie. myfile01.myfile. I’m using binary serialization (not xml).

In version 1 of this class, there was a field ‘ColoredFont’. This is a class that contains a Font and a Color.

In version 2 of the class, the class ColoredFont was changed, and the ‘Font’ field was replaced by ‘SerializableFont’.

Now the problem: when i want to open version 1 files, I get an error :

 Object of type 'System.Drawing.Font' cannot be converted to 
 type 'Project.SerializableFont'.

I already use a custom serialization binder

public class Binder : SerializationBinder {

    public override Type BindToType(string assemblyName, string typeName) {
        Type tyType = null;
        string sShortAssemblyName = assemblyName.Split(',')[0];
        Assembly[] ayAssemblies = AppDomain.CurrentDomain.GetAssemblies();
        if (sShortAssemblyName.ToLower() == "project"
            || sShortAssemblyName == "SoftwareV_3.0"  )
        {
            sShortAssemblyName = "SoftwareV_4.0";
        }
           foreach (Assembly ayAssembly in ayAssemblies) {
               if (sShortAssemblyName == ayAssembly.FullName.Split(',')[0]) {
                tyType = ayAssembly.GetType(typeName);
                break;
            }
        }
        return tyType;
    }
}

How I can tell the deserialization to convert System.Drawing.Font to SerializableFont ??

  • 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-26T10:12:23+00:00Added an answer on May 26, 2026 at 10:12 am

    Try this for the ColoredFont class :

    [Serializable]
    public class ColoredFont : ISerializable
    {
        public SerializableFont SerializableFont;
        public Color Color;
    
        private ColoredFont(SerializationInfo info, StreamingContext context)
        {
            Color = (Color)info.GetValue("Color", typeof(Color));
            try
            {
                SerializableFont = (SerializableFont)info.GetValue("SerializableFont", typeof(SerializableFont));
            }
            catch (SerializationException serEx)
            {
                Font f = (Font)info.GetValue("Font", typeof(Font));
                // do something to initialize SerializedFont from 'f'
            }
    
        }
    
        #region ISerializable Members
    
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("SerializableFont", SerializableFont);
            info.AddValue("Color", Color);
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml file.i need to serialize to c# class. <Configs> <Services> <Path>
I have the following class that I want to serialize to an XML file
I have a class which is serialized to and from an XML file when
I have a class that I need to binary serialize. The class contains one
I have a class, SerializableColor, to allow me to XML serialize Colors. public class
I have a business class which I need to serialize to xml. It has
In my project I have a class which I Serialize in Binary format to
I have created a C# class file by using a XSD-file as an input.
I have an XML File that I am processing using LINQ. I want to
I have a template class that I serialize (call it C), for which I

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.