API Questions on Kentico API.
Version 5.x > API > Server Application Unavailable View modes: 
User avatar
Member
Member
naveed.anjum-moftak - 9/5/2011 1:31:48 AM
   
Server Application Unavailable
Hi,

Whenever i try to call CMSContext.Init() function in order to save some thing in kentico db, my server gets unavailable to me and again i need to restart it. When i search other pages of the same site where i haven't call CMSContext.Init(), it works fine. Can you please tell me how can i get rid of that problem?

Kind Regards

Naveed Anjum

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 9/5/2011 1:52:53 AM
   
RE:Server Application Unavailable
Hi Naveed,

It can cause problems, if a code calls CMSContext.Init() more than once.

You can create a static variable in your custom code and set it to true after you call the CMSContext.Init() method (Init and variable setting should be done in the lock) and do not call CMSContext.Init() again if this variable is set to true.

The version 6.0 will ensure that this method will be called only once (it will be able to check if it was already called).

Best regards,
Helena Grulichova

User avatar
Member
Member
naveed.anjum-moftak - 9/6/2011 7:57:47 AM
   
RE:Server Application Unavailable
Hi Helena,

Thanks for your quick response!

I have debug my application thoroughly to check CMSContext.Init() method for multiple calls. I have write it in my web farm page load method and this method is called only once as the page loads. When i try to call the method, it runs successfully and then throws exception:

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

and my application becomes unavailable to me.

Can you please help me to resolve the issue in any other way?

Thanks

Kind Regards
Naveed Anjum

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 9/7/2011 3:50:07 AM
   
RE:Server Application Unavailable
Hi Naveed,

Usually, this error is thrown if there is an infinite loop in the code. Could you please check your code? Have your tried to implement the mentioned workaround with a static variable?

Best regards,
Helena Grulichova

User avatar
Member
Member
naveed.anjum-moftak - 9/7/2011 4:34:07 AM
   
RE:Server Application Unavailable
There is no loop at all in my code. I am just calling CMSContext.Init() once the page loads. I haven't try the static variable workaround as you mentioned earlier. Let me try that also and let you know!

Kind Regards
Naveed Anjum