This project is read-only.

What does this error mean?

Nov 26, 2010 at 4:15 AM

I get the following error when I do a simple example use. - The SimpleServiceLocator can't be changed after the first call to GetInstance and GetAllInstances

The code is as follows:

            // 1. Create a new Simple Service Locator container
            var container = new CuttingEdge.ServiceLocation.SimpleServiceLocator();
            // 2. Configure the container (see below)
            // 3. Optionally validate the container's configuration.
            // 4. Register the container to the Common Service Locator
            Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => container);

            IvcDBServices containerinstDB = new IvcDBServices();
            container.RegisterSingle<IvcDBServices>();  <--------------  DIES here
I'm confused since I made no calls to GetInstance directly.

Nov 26, 2010 at 7:40 AM

Hi Dewey,

The container locks itself for any changes after the first call to GetInstance or GetAllInstances. You can't register anything after this point.  The Validate method internally also locks the container, which might be a bit confusing. At least the exception should explain this and perhaps the samples could be a little bit more clearer about this.

The solution is to move the registrations before the call to container.Validate().

Thanks for bringing this up.

Marked as answer by dot_NET_Junkie on 11/3/2013 at 11:44 PM
Nov 26, 2010 at 8:42 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.