OpenAccess Error: Value cannot be null. Parameter name: con

Thread is closed for posting
5 posts, 1 answers
  1. NemFontos
    NemFontos avatar
    10 posts
    Member since:
    Sep 2012

    Posted 21 Mar 2009 Link to this post

    OA throws this exception (I think this is some reflection and constructor-related problem) when I build that code:

    public class Persisted  
    {  
        protected Guid id;  
        protected int version;  
    }  
     
    [Serializable]  
    [Persistent(IdentityField = "_id", VersionField = "_version")]  
    public class A : Persisted  
    {  
        private string name;  
        ....  

    I want to create a base class for my DAL classes (to call a method to fill the lazy fields before serializing). 

    How can I do that?

    Thanx!

  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 23 Mar 2009 Link to this post

    Hi NemFontos,
    You have to mark the base class also as persistent and map it 'horizontal' in the forward mapping dialog.

    We will make the exception a líttle more readable.

    Greetings,
    Jan Blessenohl
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. NemFontos
    NemFontos avatar
    10 posts
    Member since:
    Sep 2012

    Posted 23 Mar 2009 Link to this post

    Hi Jan,

    thank you, but I don't need to persist the base class, I'm just need it to provide common functionality and the "version" field.

    As you see on the other thread (telerik.com/community/forums/orm/general-discussions/objectnetworkattacher-vs-datacontractserializer.aspx) I have problem with the lazy "version" value.

    To avoid lazy loading, I can define the "version"  field in my base class and call it before serializing:

    [OnSerializing]  
    protected void BeforeSerialize(StreamingContext ctx)  
    {  
         int tmp = Version;  

    Sorry if I'm too lame and can't understand something very trivial.

    Thanx in advance,

    NemFontos

  4. Answer
    Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 23 Mar 2009 Link to this post

    Hi NemFontos,
    We can only store data in fields of an persistent class. If the base class is not marked as persistent we will not store the content of the id and version field. In your case the id and version field is not stored, which produces the weird exception.

    Greetings,
    Jan Blessenohl
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. NemFontos
    NemFontos avatar
    10 posts
    Member since:
    Sep 2012

    Posted 23 Mar 2009 Link to this post

    Thank you!
Back to Top