【问题标题】:System.MissingMethodException in a dll when I shut down c# application当我关闭 c# 应用程序时,dll 中的 System.MissingMethodException
【发布时间】:2016-11-24 17:09:27
【问题描述】:

我发现了这个错误,因为我在 windows 内置的事件查看器中看到了它:

描述:进程因未处理的异常而终止。 异常信息:System.MissingMethodException 堆: 在 Injection.Main.DrawText_Hooked(...)

我有一个使用 easyhook 的 c# 应用程序。我的 dll 关键代码:

        public void Run(RemoteHooking.IContext InContext, String InChannelName)
    {
        // Install system hook to detect calls to DrawTextExW that is made by the client and call the function DrawText_Hooked when ever this happens
        try
        {
            DrawTextExHook = LocalHook.Create(LocalHook.GetProcAddress("user32.dll", "DrawTextExW"), new DDrawTextEx(DrawText_Hooked), this);
            DrawTextExHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
        }....

我处理挂钩函数的委托是:

        int DrawText_Hooked(...)
    {
            Interface.Read(hdc, lpString, cchText, dwDTFormat);

        return DrawTextExW(hdc, lpString, cchText, ref lprc, dwDTFormat, ref dparams);
    }

当我关闭我的主应用程序时,一切正常,除非我使用Interface.Read(...):在这种情况下,挂钩的应用程序会崩溃。我读过它可能是因为一旦我退出我的应用程序,Interface.Read(...) 将不再存在,但我不知道如何告诉我的 dll 停止这样做或简单地卸载,以便它不会尝试执行 Interface.Read(...)并发现它实际上不再存在。我该怎么做?

【问题讨论】:

    标签: c# dll missingmethodexception


    【解决方案1】:

    两天寻找答案,发布后我在 10' 后自己发现:

    我所做的是将钩子声明为静态:

            static LocalHook DrawTextExHook;
    

    所以从我的主代码中,在退出时,我可以调用一个指向null 的静态方法,因此停止调用我的Interface.Read(...)

            public static void stopIt()
        {
            DrawTextExHook = null;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 2019-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多