升级到.NET框架后,在64位Windows Server 2012溢出错误? [英] Overflow Errors in 64-bit Windows Server 2012 after Upgrade to .NET Framework?

查看:183
本文介绍了升级到.NET框架后,在64位Windows Server 2012溢出错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的解决方案最近从.NET框架3.5版升级到v4.5.2,因此我们不得不在Windows Server 2012上运行64位机器的一些溢出错误。

Our solution was recently upgraded from .NET Framework v3.5 to v4.5.2 and as a result we have had some overflow errors running on Windows Server 2012 64-bit machines.

这些溢出错误似乎是从这里我们称之为从Windows API此功能的任何实例来了:

These overflow errors seem to be coming from any instance where we call this function from the Windows API:

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);

溢出是在某些情况下发生的,因为lParam的,不管是什么原因,它被传递一个int,而不是一个IntPtr尽管该函数需要一个IntPtr。

The overflow was happening because for lParam in some instances, for whatever reason, it was being passed an int instead of an IntPtr even though the function expects an IntPtr.

什么是有趣的是升级.NET和仅在Windows Server后才能体现这些问题2012 64位的机器。

What was interesting was these issues only manifested after upgrading .NET and ONLY on Windows Server 2012 64-bit machines.

我试图破译原因这只在这种情况下发生的,并且还试图寻找寻找到可能发生这种溢出错误的其他情况下的有效途径。

I'm trying to decipher the cause for this only happening under these circumstances, and also trying to find an effective way to find where other instances of this kind of overflow error could occur.

我首先想到的是要寻找在那里SendMessage函数被调用的所有实例,但这可能会错过在这里的IntPtr被误用一些其他的情况。我的另一个想法是为使用ReSharper的或FxCop的,以检测这些类的实例,并提醒我给他们,但我不知道如何,或者如果这是可能的,默认情况下ReSharper的是不给任何投诉。

My first thought was to look for all instances where SendMessage was being called, but this could miss some other instances where IntPtr is being misused. My other idea was to use either ReSharper or FXCop to detect these sort of instances and alert me to them, but I don't know how or if this is possible and by default ReSharper isn't giving any complaints.

推荐答案

您应该使用的IntPtr 而不是 INT 因为 SendMessage函数函数的最后两个参数是指针。请参见 Windows数据类型关于 WPARAM LPARAM 类型。

You should use IntPtr instead of int because the last two arguments of the SendMessage function are pointers. See Windows Data Types about WPARAM and LPARAM types.

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

这篇关于升级到.NET框架后,在64位Windows Server 2012溢出错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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