Last post Mar 15, 2012 03:02 PM by Cathy Mi - MSFT
Feb 10, 2012 07:51 PM|54sun|LINK
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:
ViewState["Records"] = existingRecords;
Please tell me how I can solve this problem.
Feb 12, 2012 02:36 AM|Decker Dong - MSFT|LINK
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。
Feb 15, 2012 11:29 AM|54sun|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 error
and in the .dbml cs file, I added:
public partial class TestClass
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=22.214.171.124, Culture=neutral, PublicKeyToken=null]]' in Assembly 'System.Data.Linq, Version=126.96.36.199, 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?
Feb 16, 2012 02:31 AM|Decker Dong - MSFT|LINK
Or say, it works for one class but not another.
Plz check whether your another class has something that cannot be serialized？
Feb 16, 2012 12:14 PM|54sun|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?
Feb 20, 2012 01:25 PM|54sun|LINK
Does anyone can give suggestions on how to solving this issue?
Please mention anything that may relevant.
Thanks very much!
Feb 20, 2012 09:42 PM|Cathy Mi - MSFT|LINK
Take a look at the thread below:
Feb 29, 2012 03:01 PM|54sun|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=188.8.131.52, 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.
Mar 15, 2012 03:02 PM|Cathy Mi - MSFT|LINK
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.