零星的“方法‘get_Session’”来自程序集的类型没有实现”

发布于 2024-11-07 03:54:04 字数 2744 浏览 3 评论 0原文

突然,我开发的网络应用程序开始向用户发出此错误消息,但不是向我发出,而且只是有时发出。

我知道这个错误可能是由于接口程序集和实现程序集参考版本不匹配引起的。但我已经很长一段时间没有更新Sharp的版本了(这个项目仍然使用很旧的版本)。另外,错误并不总是发生,如果是错误的程序集,我想它总是会失败。

可能是什么原因?框架中是否有任何跟踪/登录工具可以查找?

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,所以我想这就是类型检查失败的地方。我会怀疑程序集版本,但正如我所说,它总是对我有用,有时对用户也有用。

Suddenly the web app that I develop started to give this error message - to the user, but not to me, and only sometimes.

I know that this error can be caused by interface assembly and implementation assembly reference versions mismatch. But I did not update Sharp's version for a long time (still use very old one for this project). Also, the error does not happen always, if it was wrong assemblies I suppose it would always fail.

What can be the reason? Are there any tracing/loggin tools in framework to find out?

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)

Here's the SafeSessionStorage. It is a slightly modified version of SharpArch's one, to support running in background threads.

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;
}

Here's where error happens:

  private void InitializeNHibernateSession()
  {
     NHibernateInitHelper.InitSession(safeSessionStorage,
        Server.MapPath("~/NHibernate.config"),
        Server.MapPath("~/bin/Orders.Data.dll"));
  }

Here InitSession expects ISessionStorage and is passed SafeSessionStorage, so I suppose that's where type checking fails. And I would suspect assemblies versions but, as I said, it always works for me and sometimes works for the user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失退 2024-11-14 03:54:04

我最好接受sehe的评论作为答案,但无论如何。该问题是由于递归数据库数据而导致的 StackOverflowException。为了调试这个问题,我必须向可疑代码中的许多行添加日志记录(错误发生在 SOAP 服务访问和使用 DB 映射数据上),然后进行分析。另一种方法是部署调试版本(这是开发服务器)并使用 WinDbg,它给出了正确的异常代码 0xe053534f,以便我可以专注于可能导致此问题的代码(递归 LINQ 方法来收集相关产品)。

驱动器空间不足是 DW20.exe (dr. watson) 占用 1.5 GB 空间(和 CPU)的副作用。

事件查看器有点帮助,因为它显示了过于通用的“kernel32.dll,地址 0x0000bee7”错误,可能是堆栈溢出,也可能是其他任何情况。

得到“方法没有实现”是我期望从这种情况中得到的最后信息。

I would better accept sehe's comment as answer, but anyway. The problem was a StackOverflowException because of recursive DB data. To debug this I had to add logging to many lines inside the suspected code (the error happened on SOAP service acccess and mapping data using DB), and then analyze. Another approach was to deploy debug build (this is dev server) and use WinDbg, which gave correct exception code 0xe053534f so that I could concentrate on code that may cause this (recursive LINQ method to collect related products).

The low drive space was a side effect of DW20.exe (dr. watson) eating 1.5 GB space (and CPU).

Event viewer was a little help because it showed the too generic "kernel32.dll, address 0x0000bee7" error that could be stack overflow and could be anything else.

Getting "method does not have implementation" is the last information I'd expect from such conditions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文