db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join
in Search
More Search Options

Dictionary object not storable on .NET

Last post 12-03-2008, 12:40 AM by Adriano Verona. 4 replies.
Sort Posts: Previous Next
  •  11-16-2008, 12:10 PM 52031

    Dictionary object not storable on .NET

    I added this piece of code to Pilot class as an simplified example of the issue in my hands:

    System.Collections.Generic.Dictionary<string, long> _gen = new System.Collections.Generic.Dictionary<string, long>();

    public System.Collections.Generic.Dictionary<string, long> Gen

    {

    get { return _gen; }

    set { _gen = value; }

    }

     and execute this:

    Db4oFactory.Configure().ExceptionsOnNotStorable(true);

     

    IObjectContainer db = Db4oFactory.OpenFile(@"c:\temp\testi.yap");

    try

    {

    Pilot pilot = new Pilot("testi", 1);

    db.Set(pilot);

    }

    catch(Exception e)

    {

    Console.WriteLine(e.Message);

    }

    finally

    {

    db.Close();

    }

     On version 6.4.54.11278 and below it works just fine, but on version 7.4.68.12069 this gives exception:

    Add constructor that won't throw exceptions, configure constructor calls, or provide a translator to class 'System.Collections.Generic.Dictionary`2+KeyCollection[[System.String, mscorlib], [System.Int64, mscorlib]], mscorlib' and make sure the class is deployed to the server with the same package/namespace + assembly name.

     Any idea what this is?

  •  11-16-2008, 12:38 PM 52032 in reply to 52031

    Re: Dictionary object not storable on .NET

    Hmm - looks like I need to use this on 7.4:

    Db4oFactory.Configure().ObjectClass(typeof(Dictionary<string, long>)).Translate(new Db4objects.Db4o.Config.TDictionary());

    But when reading the reference documenation it states this:

    In general you will never need to use any of these translators as all the work is done for you under the hood. 

    So the actual bug is related to this statement, automatic usage of this does not work?

  •  11-19-2008, 06:12 PM 52081 in reply to 52032

    Re: Dictionary object not storable on .NET

    Hi.

    I really don't think that translators are required for this scenario.

    Could you test your code (without the translator) against trunk (7.7)
    and let us know how it goes?

    Meanwhile I'll try to reproduce it (in 7.4).

    Thanks

    Adriano

    juvander wrote:
    > Hmm - looks like I need to use this on 7.4:
    >
    > Db4oFactory.Configure().ObjectClass(typeof(Dictionary
    > long>)).Translate(new Db4objects.Db4o.Config.TDictionary());
    >
    > But when reading the reference documenation it states this:
    >
    > In general you will never need to use any of these translators as
    > all the work is done for you under the hood.
    >
    > So the actual bug is related to this statement, automatic usage of this
    > does not work?
    >
    >
    > ------------------------------------------------------------------------
    > http://developer.db4o.com/forums/52031/ShowThread.aspx#52032
    >
  •  11-19-2008, 06:26 PM 52082 in reply to 52081

    Re: Dictionary object not storable on .NET

    Works with 7.7 without the translator, with 7.4 it fails.

    //Ilpo

  •  12-03-2008, 12:40 AM 52219 in reply to 52082

    Re: Dictionary object not storable on .NET

    Hi,

    Probably you have configured ExceptionsOnNotStorable and TestConstructors, right?

    In .Net we try to avoid recreating objects by calling its constructors since we are going to set each field (so we use FormatterServices.GetUninitializedObject()).

    For collections (in version 7.4) unfortunately we do need to call its constructors (we need a valid collection in order to add elements to it).

    (I guess that we had traslators in 6.4)

    As a fix you can either set ExceptionsOnNotStorable / TestConstructors to false (or both) (personaly I'd go with TestConstructors).

    Note that with the introduction of new typehandlers for generics collections, in 7.7 this scenario works just fine (inclusive we set these configurations to true by default).

    Adriano

View as RSS news feed in XML