Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Strange Error
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Miscellaneous
Thread ID:
01437935
Message ID:
01438013
Views:
43
Hi,

Not sure of the answer to this. The basic problem appears to be that the design time serialization of your UserControl is attempting to also serialize the Address class but not knowing the UserControl code I don't know why this is happening (and there's probably no reason why you would want this anyway?)
Maybe you can use an atttribute of the reference to the Address class to prevent serialization? :
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

Or, maybe simpler, instantiate the Address class in the constructor of the UserControl?

Sorry if this doesn't help - it's a long time since I worked on WinForms custom controls :-{

Regards,
Viv

>Ok, it's a bit long, but here it is:
>
>
>using System;
>using System.Collections.Generic;
>using System.Linq;
>using System.Text;
>using System.Data.SqlClient;
>using System.Collections;
>using System.Data;
>
>namespace Marois.WorkIT.DataAccess
>{
>    [Serializable]
>    public class Address : DataClassBase
>    {
>        private int _AddressTypeKey = 0;
>        public int AddressTypeKey
>        {
>            get { return _AddressTypeKey; }
>            set { _AddressTypeKey = value; }
>        }
>
>        private string _Street1 = string.Empty;
>        public string Street1
>        {
>            get { return _Street1; }
>            set { _Street1 = value; }
>        }
>
>        private string _Street2 = string.Empty;
>        public string Street2
>        {
>            get { return _Street2; }
>            set { _Street2 = value; }
>        }
>
>        private string _City = string.Empty;
>        public string City
>        {
>            get { return _City; }
>            set { _City = value; }
>        }
>
>        private string _State = string.Empty;
>        public string State
>        {
>            get { return _State; }
>            set { _State = value; }
>        }
>
>        private string _PostalCode = string.Empty;
>        public string PostalCode
>        {
>            get { return _PostalCode; }
>            set { _PostalCode = value; }
>        }
>    
>        public override void LoadData()
>        {
>            DataSet ds = AppDataAccess.GetAddresses(this.RecordId);
>
>            if (ds != null && ds.Tables.Count > 0)
>            {
>                this.RecordId = Convert.ToInt32(ds.Tables[0].Rows[0]["AddressKey"]);
>                _AddressTypeKey = Convert.ToInt32(ds.Tables[0].Rows[0]["AddressTypeKey"]);
>                _Street1 = ds.Tables[0].Rows[0]["Street1"].ToString();
>                _Street2 = ds.Tables[0].Rows[0]["Street2"].ToString();
>                _City = ds.Tables[0].Rows[0]["City"].ToString();
>                _State = ds.Tables[0].Rows[0]["State"].ToString();
>                _PostalCode = ds.Tables[0].Rows[0]["PostalCode"].ToString();
>
>            }
>
>            else
>            { 
>                this.DataException = AppDataAccess.DataException;
>            }
>        }
>       
>
>        public override void Delete()
>        {
>            SqlParameter pAddressKey = new SqlParameter("@AddessKey", this.RecordId);
>            ArrayList colParams = new ArrayList();
>            colParams.Add(AddressTypeKey);
>
>            AppDataAccess.ExecuteNonQuery("wit_DeleteAddress",colParams);
>
>            if (AppDataAccess.DataException == null)
>            {
>                this.RecordId = 0;
>                _AddressTypeKey = 0;
>
>            }
>            else
>            {
>                this.DataException = AppDataAccess.DataException;
>            }
>
>        }
>
>        public override bool SaveChanges()
>        {
>            bool RetVal = Validate();
>
>            if (RetVal)
>            {
>                string ProcName = string.Empty;
>
>                SqlParameter pAddressKey = new SqlParameter("@AddressKey", 0);
>
>                if (this.RecordId == 0)
>                {
>                    pAddressKey.Direction = ParameterDirection.Output;
>                    ProcName = "wit_AddAddress";
>                }
>                else
>                {
>
>                    pAddressKey.Value = this.RecordId;
>                    ProcName = "wit_UpdateAddress";
>                }
>               
>                SqlParameter pAddressTypeKey = new SqlParameter("@AddressTypeKey",_AddressTypeKey);
>                SqlParameter pStreet1 = new SqlParameter("@Street1", _Street1);
>                SqlParameter pStreet2 = new SqlParameter("@Street2", _Street2);
>                SqlParameter pCity = new SqlParameter("@City", _City);
>                SqlParameter pState = new SqlParameter("@State", _State);
>                SqlParameter pPostalCode = new SqlParameter("@PostalCode", _PostalCode);
>
>                ArrayList colParams = new ArrayList();
>                colParams.Add(pAddressKey);
>                colParams.Add(pAddressTypeKey);
>                colParams.Add(pStreet1);
>                colParams.Add(pStreet2);
>                colParams.Add(pCity);
>                colParams.Add(pState);
>                colParams.Add(pPostalCode);
>
>                AppDataAccess.ExecuteNonQuery(ProcName, colParams);
>
>                if (AppDataAccess.DataException == null)
>                {
>
>                    if (pAddressKey.Direction == ParameterDirection.Output)
>                    {
>                        this.RecordId = Convert.ToInt32(pAddressKey.Value);
>                    }
>                }
>                else
>                {
>                    this.DataException = AppDataAccess.DataException;
>                }
>            }
>
>            return RetVal;
>        }
>
>        public override bool Validate()
>        {
>            bool bValid = true;
>
>            if (_AddressTypeKey == 0)
>            {
>                bValid = false;
>                base.DataException = new DataValidationException("Address can not be empty");
>            }
>            return bValid;
>        }
>    }
>}
>
>
>>No change at all? Are you sure - the error is pretty specific:
'System.Runtime.Serialization.SerializationException: Type 'Marois.WorkIT.DataAccess.Address' in Assembly 'DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
Marking it as serializable should get rid of that error but if any of the properties of the Address class were not serializable you may get a different error. Can you post the code for the class?
>>
>>
>>>Done. No change.
>>>
>>>
>>>>As a first step try adding the [Serializable] attribute to the Address class
>>>>
>>>>>I have multiple projects in my WinForms solution.
>>>>>
>>>>>I have a class called Address in a project called DataAccess. This class has properties for each field in the address table. In the project WorkIT I have a user control called crlAddress that is the UI to the Address class.
>>>>>
>>>>>When I try to drag the crlAddress control into the crlCustomer control, I get the following:
>>>>>
>>>>>
>>>>>Failed to create component 'crlAddresses'.  The error message follows:
>>>>>
>>>>> 'System.Runtime.Serialization.SerializationException: Type 'Marois.WorkIT.DataAccess.Address' in Assembly 'DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
>>>>>
>>>>>   at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
>>>>>
>>>>>   at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
>>>>>
>>>>>   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
>>>>>
>>>>>   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
>>>>>
>>>>>   at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
>>>>>
>>>>>   at System.Runtime.Serialization.Formatters.Bina...'
>>>>>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform