System.MissingMethod当我关闭c#应用程序时,在dll中出现异常 [英] System.MissingMethodException in a dll when I shut down c# application

查看:708
本文介绍了System.MissingMethod当我关闭c#应用程序时,在dll中出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


说明:该进程已终止由于未处理的异常。
异常信息:System.MissingMethodException
堆栈:
在Injection.Main.DrawText_Hooked(...)



$ b $我有使用easyhook的ac#应用程序。我的dll关键代码:

  public void Run(RemoteHooking.IContext InContext,String InChannelName)
{
//安装系统挂钩来检测客户端所做的DrawTextExW的调用,并在发生这种情况时调用函数DrawText_Hooked
try
{
DrawTextExHook = LocalHook.Create(LocalHook.GetProcAddress( user32.dll,DrawTextExW),新的DDrawTextEx(DrawText_Hooked),这个);
DrawTextExHook.ThreadACL.SetExclusiveACL(new Int32 [] {0});
} ....

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

  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(...),并发现它实际上并不存在。我应该怎么做?

解决方案

两天内寻找答案,发布后我会在10点后发现自己: / p>

我所做的是声明挂钩静态:

  static LocalHook DrawTextExHook; 

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

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


I found out about the error because I saw it in the windows built-in event viewer:

Description: The process was terminated due to an unhandled exception. Exception Info: System.MissingMethodException Stack: at Injection.Main.DrawText_Hooked(...)

I have a c# application using easyhook. My dll critical code:

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

And my delegate to handle the hooked function is:

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

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

When I shut down my main application everything works fine unless I use Interface.Read(...): in this case, the hooked application crashes. I've read it's probably because Interface.Read(...) doesn't exist anymore once I exit my app but I don't know how to tell my dll to stop doing that or simply unload so that it doesn't try to do Interface.Read(...) and finds out it doesn't actually exist anymore. How shall I do it?

解决方案

Two days looking for the answer and after posting it I discover it myself after 10':

What I did was to declare the hook static:

        static LocalHook DrawTextExHook;

So from my main code, on exit, I could call a static method that points it to null, therefore stopping calling my Interface.Read(...).

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

这篇关于System.MissingMethod当我关闭c#应用程序时,在dll中出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆