Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
first ,please look my exception infos in below:
exception time:2013-10-15 09:08:30,765 [1] 
exception level:ERROR 
exception class:logerror [(null)] 
SpringFactory.GetObject(adminFacade) 
 System.InvalidOperationException: root context is currently in creation. You must not call ContextRegistry.GetContext() from e.g. constructors of your singleton objects
   at Spring.Context.Support.ContextRegistry.InitializeContextIfNeeded()
   at Spring.Context.Support.ContextRegistry.GetContext()
   at Domain.common.SpringFactory.GetObject(String objectId) in F:\gitlab\huatongmis.git\HuaTongBusinessWeb\Domain\common\SpringFactory.cs:line 38


there are some exception infos like that in my project log files,actually it does not make my project break down. but I treat it as a terrible problem.it puzzled me for a long time.

please see the exception point in my code file.
C#
public class SpringFactory
    {
        private static IApplicationContext _applicationContext;

        private SpringFactory(){}


        public static Object GetObject(string objectId)
        {
            try
            {
                if (_applicationContext == null)
                {
                    _applicationContext = ContextRegistry.GetContext();
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(string.Format("SpringFactory.GetObject({0})",objectId), ex);
            }
            return _applicationContext.GetObject(objectId);
        }
    }


I use the IOc just like this
C#
public class Order : System.Web.Services.WebService
    {
        public HTSoapHeader htSoapHeader;
        private OrderFacade orderFacade { get; set; }
        private TicketFacade ticketFacade { get; set; }
        private CarrentalFacade carrentalFacade { get; set; }
        private AdminFacade adminFacade { get; set; }
        public Order()
        {
            orderFacade = (OrderFacade)SpringFactory.GetObject("orderFacade");
            ticketFacade = (TicketFacade)SpringFactory.GetObject("ticketFacade");
            carrentalFacade = (CarrentalFacade)SpringFactory.GetObject("carrentalFacade");
            adminFacade = (AdminFacade)SpringFactory.GetObject("adminFacade");
        }
}


how it happened and how to solve the problem.
looking forward to having your any answer, thanks
Posted
Comments
Richard MacCutchan 17-Oct-13 5:21am    
The message is telling you what you must not do.
Member 10188921 17-Oct-13 6:03am    
how to eliminate that exception.and what is the correct usage
Richard MacCutchan 17-Oct-13 6:08am    
Remove it from your factory method and place it in a later part of the start up code. I would strongly suggest you read the Spring.NET documentation for further details.
Member 10188921 10-Nov-13 0:13am    
thank u for you answer,I found the root cause which result in that exception.It's my IIS.my project is deploied on iis7.0 with integrerad pipeline mode.But during initialization of the spring IOC container,there is a action that rewriting Httpcontext.Unfortunately, In the pipe events of application such as the constructor of Global,and the Application_Start event.the httpcontext is not initialized in The IIS7.0 integrerad pipeline mode. that is the root cause which giving the exception.

1 solution

thank u for you answer,I found the root cause which result in that exception.It's my IIS.my project is deploied on iis7.0 with integrerad pipeline mode.But during initialization of the spring IOC container,there is a action that rewriting Httpcontext.Unfortunately, In the pipe events of application such as the constructor of Global,and the Application_Start event.the httpcontext is not initialized under The IIS7.0 integrerad pipeline mode. that is the root cause which giving the exception.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900