突然间,我开发的 Web 应用程序开始向用户提供此错误消息,但不是对我,而且只是有时。
我知道这个错误可能是由接口程序集和实现程序集参考版本不匹配引起的。但是我很长时间没有更新夏普的版本(这个项目仍然使用很旧的版本)。此外,错误并不总是发生,如果是错误的程序集,我想它总是会失败。
可能是什么原因?框架中是否有任何跟踪/登录工具可以查找?
Method 'get_Session' in type 'Orders.Data.SafeSessionStorage'
from assembly 'Orders.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
does not have an implementation."
System.TypeLoadException: Method 'get_Session' in type 'Orders.Data.SafeSessionStorage' from assembly 'Orders.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
at Orders.Web.MvcApplication.InitializeNHibernateSession()
at Orders.Web.MvcApplication.<Application_BeginRequest>b__1d()
at SharpArch.Data.NHibernate.NHibernateInitializer.InitializeNHibernateOnce(Action initMethod)
at Orders.Web.MvcApplication.Application_BeginRequest(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
这是 SafeSessionStorage。它是 SharpArch 的稍作修改的版本,以支持在后台线程中运行。
public class SafeSessionStorage : ISessionStorage
{
[ThreadStatic]
private static ISession _session;
public ISession Session
{
get
{
HttpContext context = HttpContext.Current;
if (context == null)
return _session;
else
{
ISession session = context.Items[factoryKey] as ISession;
return session;
}
}
set
{
HttpContext context = HttpContext.Current;
if (context == null)
_session = value;
else
context.Items[factoryKey] = value;
}
}
public string FactoryKey
{
get { return factoryKey; }
}
public static void End()
{
if (_session != null)
_session.Close();
_session = null;
}
public void EndRequest()
{
ISession session = Session;
if (session != null)
{
session.Close();
HttpContext context = HttpContext.Current;
if (context != null)
context.Items.Remove(factoryKey);
else
_session = null;
}
}
private string factoryKey = NHibernateSession.DefaultFactoryKey;
}
这是发生错误的地方:
private void InitializeNHibernateSession()
{
NHibernateInitHelper.InitSession(safeSessionStorage,
Server.MapPath("~/NHibernate.config"),
Server.MapPath("~/bin/Orders.Data.dll"));
}
这里 InitSession 需要 ISessionStorage 并通过 SafeSessionStorage,所以我想这就是类型检查失败的地方。我会怀疑程序集版本,但正如我所说,它总是对我有用,有时也对用户有用。