Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:22:07+00:00 2026-06-15T09:22:07+00:00

I am wondering: if I load an object from a db4o database, will field

  • 0

I am wondering: if I load an object from a db4o database, will field initializers always be called?

An example could be a transient field syncRoot, used for object locking, because of thread-safety:

public class Test
{
    [Transient]
    private object syncRoot = new object();

    [Transient]
    private object syncRoot2;

    public Test()
    {
        this.syncRoot2 = new object();
    }
}

The db4o query is like:

Test mytestObject = (from Test test in session
                     select test).First(); 

I can’t use syncRoot2 because during the db4o query, the object constructors are not called, so the value will be null. But what about syncRoot? Is it safe to use field initializers on db4o model objects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:22:09+00:00Added an answer on June 15, 2026 at 9:22 am

    It depends 🙂

    By default no, since db4o will try to avoid calling the ctor and field initializers are executed within the ctor) (at least using C# compiler shipped with VS 2010).

    For example, given the following class definition:

    public class Item
    {
       public object o = new object();
    }
    

    C# compiler will emit IL (for the constructor) similar to:

    .class public auto ansi beforefieldinit Item extends [mscorlib]System.Object
    {
       .field public object o
       .field public notserialized int32 i
    
       .method public hidebysig specialname rtspecialname 
                      instance void .ctor () cil managed 
       {
            .maxstack 8
    
            ldarg.0
            newobj instance void [mscorlib]System.Object::.ctor()  // field initializer
            stfld object Item::o // field initializer
            ldarg.0
            call instance void [mscorlib]System.Object::.ctor()
            ret
       }
    }
    

    Basically you have two options here:

    1. Enable constructor invocations
    2. Use Activated event to initialize the transient fields.

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this from Load web browser with web response . and am wondering
I'm attempting to load a User object from mysql but I keep getting UnboundExecutionError:
I was wondering how to extract data from a returned object via jQuery's $.get()
I am trying to load UIImage object from NSData , and the sample code
I am wondering conceptually how load-balancing works on the EJB-level (not web session replication)
I am wondering if it is possible to load javascript in a way in
I was wondering if it was possible to load a asp.net control (.ascx) that
I am wondering how I can load a byte array into a memory URLClassLoader?
I'm just wondering why I cannot load a resource with the Thread context loader
I was wondering how I can make a script load powerpoint file, advance slides

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.