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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:40:25+00:00 2026-05-17T01:40:25+00:00

C#: Does Serializable() attribute prevent passing a class instance to another form? I have

  • 0

C#: Does Serializable() attribute prevent passing a class instance to another form?

I have the following classes, and is trying to build a settings module for my application. But when i try to access _configurator in settingForm method i get an exception: “object reference not set to an instance of an object”. Why?

[Serializable()]
public class Config
{
    public Config() { }
    public string ComPort
    {
        get
        {
            return comPort;
        }
        set
        {
            comPort = value;
        }
    }

    private string comPort;

}

public partial class kineticMoldDockUserControl : UserControl
{

    private settingsForm setForm = null; 

    private Config _cf = null;



    public kineticMoldDockUserControl()
    {
        InitializeComponent();

        _cf = new Config();
        _cf.ComPort = "COM12";

    }




    private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
    {



        if (!Application.OpenForms.OfType<settingsForm>().Any())
        {

            setForm = new settingsForm();

            setForm.Show();

            setForm.cf = _cf;


        }



    }


}

public partial class settingsForm : Form
{

    Config _configutor = null;
    public Config cf { get { return _configutor; } set { _configutor = value; } }


    public settingsForm()
    {
        InitializeComponent();

        try
        {
            MessageBox.Show(_configutor.ComPort.GetType().ToString());
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

     }

}
  • 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-17T01:40:26+00:00Added an answer on May 17, 2026 at 1:40 am

    You error has no relation with Serializable attribute. Problem lies in below lines of code:

                setForm = new settingsForm();
    
                setForm.Show();
    
                setForm.cf = _cf;
    

    SettingsForm constructor is using configurator but you are setting it after constructor is called. You may pass the configurator via constructor to solve your issue.

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

Sidebar

Related Questions

I have a class in my C# project marked with the [Serializable] attribute. It
I set a servlet context attribute, which is an object of Serializable class. Does
I'm trying to pass an instance of a class between two separate classes, like
If I add the [Serializable] attribute to a class, does this introduce any overhead?
Possible Duplicate: Does adding [Serializable] to the class have any performance implications? What is
I've created the following attribute: [Serializable] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited =
I have a set of classes build using xsd.exe, and I am trying to
Possible Duplicate: Why XML-Serializable class need a parameterless constructor Does anyone know if it
I have a class with numerous Nullable<T> properties which I want to be serializable
I have a whole list of entity classes which I need to make Serializable

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.