Upgrading from 2.0.2 to 2.5? Connection Factory Problem.

May 18, 2012 at 8:54 PM

I see in the breaking changes for 2.5 the LdapConnectionFactory is no longer static and it says to use LdapConfiguration.UseStateStorage(). I thought if I simply put that into my config class it would fix the problem but everytime I try and run my app I get the following error:

A static configuration and connection factory must be provided.  See LdapConfiguration.

How can I get around this? It was working fine using 2.0.2

In my Global.asax I call ApplyConfiguration() which looks like this:

 

public static void ApplyConfiguration()
        {
            LdapConfiguration config = new LdapConfiguration();
            config.UseStaticStorage();
            LdapDirectoryIdentifier directoryIdentifier = (LdapDirectoryIdentifier)DefaultConnection.Directory;
            if(DefaultCredentials == null)
                config.ConfigureFactory(directoryIdentifier.Servers[0]);
            else
                config.ConfigureFactory(directoryIdentifier.Servers[0]).AuthenticateAs(DefaultCredentials);

            AddMappings(config);
        }

        private static void AddMappings(LdapConfiguration config)
        {
            if (config != null)
            {
                config.AddMapping(new PersonClassMap());
                //config.AddMapping(new GroupClassMap());
            }
        }

 

Then in my API I wrote using your library I have my PersonRepository, which calls my ContextFactory, stores 1 instance of a context per HttpContext, this looks like this:

 

        private readonly DirectoryContext _context;
        private readonly IQueryable<TClass> _query;

        protected EntityRepository()
        {
            DirectoryContext context = ContextFactory.Current();
            _context = context;
            _query = context.Query<TClass>();
        }
ContextFactory.cs:
        public static DirectoryContext Current()
        {
            string objectContextKey = HttpContext.Current.GetHashCode().ToString("x");
            if (HttpContext.Current.Items.Contains(objectContextKey) == false)
            {
                HttpContext.Current.Items.Add(objectContextKey, new DirectoryContext());
            }

            DirectoryContext context = HttpContext.Current.Items[objectContextKey] as DirectoryContext;
            return context;
        }

It seems to be erroring out on trying to instantiate the DirectoryContext. What am I missing Mr. Hatter? Thanks!

 

Coordinator
May 21, 2012 at 1:04 AM
Edited May 21, 2012 at 1:37 AM

I mirrored your setup as closely as possible, but I was not able to reproduce this error in VS or in IIS.  Can you tell me which one is null out of LdapConfiguration.Configuration and LdapConfiugration.Configuration.ConnectionFactory?

UPDATE

Here's the project.  You'll probably have to make some tweaks to the mapping and connection factory information.  Please let me know if you get the same error.  https://docs.google.com/open?id=0B4BvZhSNNRYJSW5XRXFWYkNrWFk

May 21, 2012 at 6:40 PM

Alright, it looks like it was wrong on my end, my private nuget package feed was out of sync with the actual assemblies. Everything appears to be working now, thank you for your continue work on this project!