Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi there. I'm using Visual Studio 2022.
I have an error prompt that I had no experience with.
the program has a class named Common as follows:

C#
namespace WindowsFormsApp1
{
    public class Common
    {
        public class flanges
        {
            public string Name;
            public string Description;
            public double Size;
        }
    }


Then I use it in a user control as a List type as follows:


C#
namespace WindowsFormsApp1
{
    public partial class MyUserControl1 : UserControl
    {
        private List<common.flanges> _Flange=new List<common.flanges>();
        public List<common.flanges> Flange
        { 
            get { return _Flange; }
            set { _Flange = value; }
        }
            
        public MyUserControl1()
        {
            InitializeComponent();
        }
    }
}


It builds the program but when I try to insert it in form during edit time, I get an error prompt then I disable it to save or run the program. Note that inserting the user control through the program at the run time makes no problems.

What I have tried:

I couldn't check the assembly file. It seems that's not supported in VS2022.
Posted
Updated 13-Jun-22 19:38pm
v2
Comments
Graeme_Grant 11-Jun-22 0:11am    
What is the error message?
Member 12687352 14-Jun-22 0:43am    
Failed to create component 'MyUserControl1'. The error
message follows:
'Systerm.Runtime Serializatıon.SerIalizationException: Type
'WindowsFormsApp1.Common+Flanges In Assembly
WindowsFormsApp1, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' Is not marked as serıalizable
at
System.Runtime Serialization.FormatterServlces nternalGetSeri
alizableMembers(RuntimeType type]
at
System.Collectıons.Concurrent.ConcurrentDictionary '2.GetOrAdd(TKey key, Func 2 valueFactory)
at
System.Runtime Serializatıon.FormatterServIces.GetSerializable
Members(Type type, StreamingContext context]
at
System.Runtime Serializatıon.Formatters.Binary.WriteObjectlnfo. Initemberlnfo()
at
System.Runtime Serializatıon.Formatters.Binary.WriteObjectlnfo.
InitSerialize(Type objectType, Surrogateselector
surrogateselector, StreamingContext context,
SerObjectinfolnit serObjectinfoinit, FormatterConverter
converter, SerıalizatıonBinder binder)
at
System.Runtime Serializatıon.Formatters.Binary.ObJectWriter
WriteArray(WriteObjectinfo objectlnfo, Namelnfo
memberNameinfo, WriteObjectlnfo
Richard MacCutchan 11-Jun-22 3:33am    
"I get an error prompt"
And what does it say?
Member 12687352 14-Jun-22 0:43am    
Failed to create component 'MyUserControl1'. The error
message follows:
'Systerm.Runtime Serializatıon.SerIalizationException: Type
'WindowsFormsApp1.Common+Flanges In Assembly
WindowsFormsApp1, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' Is not marked as serıalizable
at
System.Runtime Serialization.FormatterServlces nternalGetSeri
alizableMembers(RuntimeType type]
at
System.Collectıons.Concurrent.ConcurrentDictionary '2.GetOrAdd(TKey key, Func 2 valueFactory)
at
System.Runtime Serializatıon.FormatterServIces.GetSerializable
Members(Type type, StreamingContext context]
at
System.Runtime Serializatıon.Formatters.Binary.WriteObjectlnfo. Initemberlnfo()
at
System.Runtime Serializatıon.Formatters.Binary.WriteObjectlnfo.
InitSerialize(Type objectType, Surrogateselector
surrogateselector, StreamingContext context,
SerObjectinfolnit serObjectinfoinit, FormatterConverter
converter, SerıalizatıonBinder binder)
at
System.Runtime Serializatıon.Formatters.Binary.ObJectWriter
WriteArray(WriteObjectinfo objectlnfo, Namelnfo
memberNameinfo, WriteObjectlnfo

C# is case sensitive: Common is not the same as common.
So this:
C#
public class Common
   {
   public class flanges
      {
      ....
      }
Does not match with this:
C#
private List<common.flanges> _Flange=new List<common.flanges>();


It's also considered good practive to start Class names with an Upper case character: class Common is correct, class common is not
 
Share this answer
 
Comments
Member 12687352 10-Jun-22 19:14pm    
That was my mistake while I was typing the question. Sorry. The letter cases are correct in VS program.
I loaded up a project and ran your code modified and works as expected. Here is the code that I used:

1. Flange Class (changed fields to properties)
C#
public class Flange
{
    public string Name { get; set; }
    public string Description { get; set; }
    public double Size { get; set; }
}

2. FlangeControl
C#
public partial class FlangeControl : UserControl
{
    private List<Flange> flanges = new();

    public List<Flange> Flanges
    {
        get => flanges;
        set => flanges = value;
    }

    public FlangeControl() => InitializeComponent();
}

3. Then I dragged and dropped the FlangeControl from the Toolbox.

4. Ran code, no errors.

Hope this helps!

PS: I am using a slightly more modern conventions.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900