1
votes

As the result of yesterday's discussion , I have decided to use Castle ActiveRecord for my ORM task. I have added attributes to the class according to the starting guide. After fixing some obvious errors, I was greeted with this:

Could not find configuration for CLASS_XXX or its root type Castle.ActiveRecord.ActiveRecordBase this is usually an indication that the configuration has not been setup correctly

Where CLASS_XXX in the error message is one of my c# class name. What is interesting is that CLASS_XXX is different each time I run the code. I have turned on log4net and my log.txt captured nothing. So, I am guessing the error occurred before the process reaches NHibernate.

Following is my CSharp code

        log4net.Config.XmlConfigurator.Configure();

        InPlaceConfigurationSource source = 
                new InPlaceConfigurationSource();


        Assembly asm = Assembly.Load("DomainModel.Entities");

        ActiveRecordStarter.Initialize(asm,source);
        ActiveRecordStarter.CreateSchema();

Any suggestion for finding the real cause of this problem?

2

2 Answers

1
votes

Either you're missing the configuration for the InPlaceConfigurationSource (sample) or you need to use a different initialization method.

1
votes

This is not likely correct:

InPlaceConfigurationSource source = new InPlaceConfigurationSource();

You need to either do something like this:

string connectionString =
  System.Configuration.ConfigurationManager.
    ConnectionStrings["Northwind"].ToString();
InPlaceConfigurationSource source =
  InPlaceConfigurationSource.Build(
    DatabaseType.MSSQLServer2005, connectionString
  );

Or something like this:

string connectionString =
    System.Configuration.ConfigurationManager.
      ConnectionStrings["Northwind"].ToString();
IDictionary<string, string> properties =
  new System.Collections.Generic.Dictionary<string, string>();
properties.Add("dialect", "NHibernate.Dialect.MsSql2005Dialect");
properties.Add("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
properties.Add("connection.provider",
  "NHibernate.Connection.DriverConnectionProvider");
properties.Add("connection.connection_string", connectionString);
properties.Add("proxyfactory.factory_class",
  "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");

InPlaceConfigurationSource source = new InPlaceConfigurationSource();
source.Add(typeof(ActiveRecordBase), (IDictionary<string, string>)properties);