+1  A: 

Your problem is here:

xmlDoc = HttpContext.Current.Application["xmlDoc"];

Try

xmlDoc = HttpContext.Current.Application["xmlDoc"] as System.Xml.XmlDocument; 
Moron
ahan thanks, how about the answer that i just posted, can you guide me which approach shall I use. I mean is there a difference between the two, both explicitly cast dont they ?
Umair
The explicit cast might throw an exception if the object it cannot be casted. Using 'as' will set the object to null. So direct cast might be slightly more performant and help catch errors faster. Using 'as' looks more readable to me though.
Moron
A: 

Got the answer after a little googling, a simple one but can be tricky for a PHP developer working on C# (as it was in my case) well i just had to explicitly cast my application state variable to XmlDocument that is at place of :

XmlDocument xmlDoc = new XmlDocument();
xmlDoc = HttpContext.Current.Application["xmlDoc"];

I used :

XmlDocument xmlDoc = new XmlDocument();
xmlDoc = (XmlDocument) HttpContext.Current.Application["xmlDoc"];

and it becomes Robust :)

can any one tell me what will be the lifetime of this ApplicationState Variable ?

Umair
Please edit your question/add a separate question if you have another question. Don't have it as part of an answer.
Moron