Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Strange Error
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Divers
Thread ID:
01437935
Message ID:
01438257
Vues:
40
Ya, but what I don't get is why I'm getting this error now. I have done this multiple times in this and other projects, and I'v never had a problem.



>You may not be trying to serialize - but the designer is (always does)
>Did you read the link I provided?
>
>>I'm not trying to do serialization!!!!!!!
>>
>>That's the issue. I don't know how this error is occuring, because I have not done anything related to it. All I'm trying to do is drop control A onto control B. Control A maintains a collection of a simple data access class.
>>
>>
>>
>>>I don't think ArrayList is serializable using the standard serializers (not enough type information).
>>>The best solution is surely to not have the designer attempt serialization in the first place.
>>>How are you referencing the Address class in the UserControl?
>>>Did you try setting the DesignerSerializationVisibility attrib as suggested?
>>>You could also try the Browsable attribute (I think, but I'm not sure, that only properties that are visible in the Properties window get serialized anyway)
>>>This link may help: http://msdn.microsoft.com/en-us/library/tk67c2t8(VS.71).aspx
>>>Regards,
>>>Viv
>>>
>>>
>>>>One thing to note...
>>>>
>>>>I change the address collection from a Generic List to an ArrayList, and the error no longer occurs. No idea why. I'd really like to use a Generic List but I can settle for an ArrayList.
>>>>
>>>>Any ideas?
>>>>
>>>>>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...'
>>>>>>>>>>
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform