NHibernate 2.0: Cfg.Configuration.SetProperties IDictionary issue

I have a problem with:

NHibernate.Cfg.Configuration.SetProperties()

      

Don't accept IDictionary: NHibernateConfigHandler

I receive messages:

Error 30 Best overloaded method match for 'NHibernate.Cfg.Configuration.SetProperties (System.Collections.Generic.IDictionary)' has some invalid arguments

and

Error 31 Argument '1': Cannot convert from 'System.Collections.IDictionary' to 'System.Collections.Generic.IDictionary'

Please inform?


The whole method:

/// <param name="config">NHibernate configuration</param>
public ISessionFactory GetSessionFactoryFor(NHibernateConfigHandler config)
{
if (config == null)
    throw new ArgumentNullException("config may not be null nor empty");

ISessionFactory sessionFactory = GetSessionFactoryFor(config.MappingAssembly);

//  Failed to find a cached SessionFactory so make a new one.
if (sessionFactory == null)
{
    NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();

    cfg.SetProperties(config.Properties); //THIS LINE

    cfg.AddAssembly(config.MappingAssembly);

    //  Now that we have our Configuration object, create a new SessionFactory
    sessionFactory = cfg.BuildSessionFactory();

    if (sessionFactory == null)
    {
        throw new InvalidOperationException("cfg.BuildSessionFactory() returned null.");
    }

    HttpRuntime.Cache.Add(config.MappingAssembly, sessionFactory, null, DateTime.Now.AddDays(7),
        TimeSpan.Zero, CacheItemPriority.High, null);
}

return sessionFactory;

      

}

0


a source to share


1 answer


SetProperties signature

public NHibernate.Cfg.Configuration SetProperties(System.Collections.Generic.IDictionary<string,string> newProperties)
    Member of NHibernate.Cfg.Configuration

      

Setproperties takes a parameter of type IDictionary, i.e. general dictionary. And you are trying to pass into IDictionary. This is the reason for the error.



Alternatively, you can change the type of properties in NHibernateConfigHandler in System.Collections.Generic.IDictionary. OR Create a System.Collections.Generic.IDictionary file and copy all values ​​from System.Collections.IDictionary.

It is always a good idea to use a generic dictionary (which is in System.Collections.Generic) over an IDictionary (which is located at System.Collections).

+1


a source







All Articles