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

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

问题描述

我们的解决方案最近从 .NET Framework v3.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<的最后两个参数/code> 函数是指针.请参阅Windows 数据类型关于 WPARAMLPARAM 类型.

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 Framework 后 64 位 Windows Server 2012 中的溢出错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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