Our application recently switched from .net 3.5 to .net 4. One issue that has cropped up is that GetWindowThreadProcessId no longer works.
Microsoft have a hotfix available, but it would be a pain to have to install that on every customer machine, and it could cause other issues. I would prefer a work around.
http://support.microsoft.com/kb/982638
The problem is, as described by microsoft:
"In a .NET Framework remoting application, you have a MarshalByRefObject object. This object contains a method that returns an IntPtr type. The object is passed across a process boundary. When the object is serialized, a SerializationException exception is thrown, and you receive the following error message: Invalid type code in stream 'Invalid' This issue occurs because the remoting code treats an IntPtr type as a primitive type when the CLR serializes the IntPtr. However, the remoting code later treats the IntPtr type as an invalid type when the Binary formatter serializes the IntPtr."
So, is there an alternative? Is there a different way for me to get a process id from a window handle? Or can I marshal my IntPtr differently to avoid this bug?