Error: No session bound to the current HttpContext
Iam trying to call call a method which having an OpenSession but its ending up with an error
"No session bound to the current HttpContext" in CurrentSesions following line
Code:
_currentSession = Instance.GetSessionFactory().GetCurrentSession();
The following is the full code of CurrentSession
Code:
public static ISession CurrentSession
{
get
{
ISession _currentSession = null;
if (System.Web.HttpContext.Current != null)
{
_currentSession = Instance.GetSessionFactory().GetCurrentSession();
}
else
{
_currentSession = SessionFactory.OpenSession();
}
return _currentSession;
}
}
and this methods are in a class names "WigleSessionManager" and its constructer is the following
Code:
private WigleSessionManager()
{
Configuration configuration = new Configuration();
configuration.Configure();
string[] Files;
string src = System.Configuration.ConfigurationSettings.AppSettings["ComponentDirectory"];
if (string.IsNullOrEmpty(src))
{
throw new Exception("System Error: ComponentDirectory key not defined in web.config");
}
Files = Directory.GetFiles(src, "*Entities.dll");
foreach (string Element in Files)
{
try
{
Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom(Element);
configuration.AddAssembly(SampleAssembly);
}
catch (Exception)
{
}
}
sessionFactory = configuration.BuildSessionFactory();
}
here in sessionFactory object is showing ENtityFetchCount,EntityLoadCount and Entity names all 0...