That solution works strangely. Or say, it works for one class but not another.
My code is
TestClass t = new TestClass();
ViewState["test"] = t; // No problem for this one
PQQ_Section2_MajorInjury p = new PQQ_Section2_MajorInjury();
ViewState["PQQ"] = p; // gets error
and in the .dbml cs file, I added:
[Serializable]
public partial class TestClass
{
}
[Serializable]
public partial class PQQ_Section2_MajorInjury
{
}
I only got an error for the second class
Type 'System.Data.Linq.EntityRef`1[[Create_Constrution_PQQ.DB_Model.PQQ_Section2, Create Constrution PQQ, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
is not marked as serializable.
Both classes are generated by Linq2Sql and I added [Serializable] for both in the partial class. But I don't know why one works while another doesn't. Did I miss something here?
I've got a lot of help from the members here.
I always use "Mark as Answer" in return.
Those two classes are both generated by Linq2Sql. I just draged them from the database to the .dbml file. And as you said, I added [Seriliasible] in the Partial class.
Please tell me how to check whether I have something that cannot be serialised in the class. I didn't add anything to the auto-generated class. Or is there datatype in the table column not support serialisation?
Thanks.
I've got a lot of help from the members here.
I always use "Mark as Answer" in return.
I have found the problem why only class: PQQ_Section2_MajorInjury gets error. This class is linked to another class PQQ_Section2 because the relationship in database.
The error acturally comes from "Type 'System.Data.Linq.EntityRef`1[ ....] in Assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
I have maked both classes Serializable, but I don't know how to deal with System.Data.Linq.EntityRef.
I've got a lot of help from the members here.
I always use "Mark as Answer" in return.
54sun
Member
128 Points
64 Posts
How to store objects of Linq to Sql generated class in ViewState?
Feb 10, 2012 06:51 PM|LINK
Hi,
I'm using Linq2sql and I gets an error when saving objets of linq2sql class into ViewState, which says "Error serializing value"
I have searched the internet and found some answers but none of them work for me. I have tried the follow:
But I still gets the same error with this code:
Please tell me how I can solve this problem.
I always use "Mark as Answer" in return.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to store objects of Linq to Sql generated class in ViewState?
Feb 12, 2012 01:36 AM|LINK
Hello:)
1)Please try to create another class with the key word——partial,and then entitled it with [Serializable]。
2)If this fails,please show us your full codes of the generated model entities。
Reguards!
54sun
Member
128 Points
64 Posts
Re: How to store objects of Linq to Sql generated class in ViewState?
Feb 15, 2012 10:29 AM|LINK
Thanks for the reply.
That solution works strangely. Or say, it works for one class but not another.
My code is
TestClass t = new TestClass(); ViewState["test"] = t; // No problem for this one PQQ_Section2_MajorInjury p = new PQQ_Section2_MajorInjury(); ViewState["PQQ"] = p; // gets errorand in the .dbml cs file, I added:
[Serializable] public partial class TestClass { } [Serializable] public partial class PQQ_Section2_MajorInjury { }I only got an error for the second class
Type 'System.Data.Linq.EntityRef`1[[Create_Constrution_PQQ.DB_Model.PQQ_Section2, Create Constrution PQQ, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
Both classes are generated by Linq2Sql and I added [Serializable] for both in the partial class. But I don't know why one works while another doesn't. Did I miss something here?
I always use "Mark as Answer" in return.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to store objects of Linq to Sql generated class in ViewState?
Feb 16, 2012 01:31 AM|LINK
Plz check whether your another class has something that cannot be serialized?
54sun
Member
128 Points
64 Posts
Re: How to store objects of Linq to Sql generated class in ViewState?
Feb 16, 2012 11:14 AM|LINK
Thanks for reply, Decker.
Those two classes are both generated by Linq2Sql. I just draged them from the database to the .dbml file. And as you said, I added [Seriliasible] in the Partial class.
Please tell me how to check whether I have something that cannot be serialised in the class. I didn't add anything to the auto-generated class. Or is there datatype in the table column not support serialisation?
Thanks.
I always use "Mark as Answer" in return.
54sun
Member
128 Points
64 Posts
Re: How to store objects of Linq to Sql generated class in ViewState?
Feb 20, 2012 12:25 PM|LINK
Does anyone can give suggestions on how to solving this issue?
Please mention anything that may relevant.
Thanks very much!
I always use "Mark as Answer" in return.
Cathy Mi - M...
Member
741 Points
165 Posts
Microsoft
Re: How to store objects of Linq to Sql generated class in ViewState?
Feb 20, 2012 08:42 PM|LINK
Hi,
Take a look at the thread below:
http://forums.asp.net/t/1176204.aspx
Thanks,
Cathy Miller
54sun
Member
128 Points
64 Posts
Re: How to store objects of Linq to Sql generated class in ViewState?
Feb 29, 2012 02:01 PM|LINK
I have found the problem why only class: PQQ_Section2_MajorInjury gets error. This class is linked to another class PQQ_Section2 because the relationship in database.
The error acturally comes from "Type 'System.Data.Linq.EntityRef`1[ ....] in Assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
I have maked both classes Serializable, but I don't know how to deal with System.Data.Linq.EntityRef.
I always use "Mark as Answer" in return.
Cathy Mi - M...
Member
741 Points
165 Posts
Microsoft
Re: How to store objects of Linq to Sql generated class in ViewState?
Mar 15, 2012 02:02 PM|LINK
Hi,
Have you resolved the problem?
If not, you probably require a more in-depth level of support. Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
Thanks,
Cathy Miller