[Solved] File.Move and PInvokeStackImbalance exception

Nov 30, 2011 at 4:41 PM

Hi,

I've been working successfully for a while with this library until I tried the File.Move method.

Every attemp results in a PInvokeStackImbalance error saying that Alphaleonis.Win32.Filesystem.NativeMethods::MoveFileWithProgressW  signature seems to be different from the native method one. I can copy/paste the exact message here but it's in french so I'm not sure it will help.

I'm working with  VS2010/.NET framwork 4.0 under windows 7.

Any advice is welcome,

Regards.

 

Nov 30, 2011 at 11:11 PM

Can you please paste a code sample from which you are calling it.

On Nov 30, 2011 11:41 AM, "brv" <notifications@codeplex.com> wrote:

From: brv

Hi,

I've been working successfully for a while with this library until I tried the File.Move method.

Every attemp results in a PInvokeStackImbalance error saying that Alphaleonis.Win32.Filesystem.NativeMethods::MoveFileWithProgressW signature seems to be different from the native method one. I can copy/paste the exact message here but it's in french so I'm not sure it will help.

I'm working with VS2010/.NET framwork 4.0 under windows 7.

Any advice is welcome,

Regards.

Read the full discussion online.

To add a post to this discussion, reply to this email (alphafs@discussions.codeplex.com)

To start a new discussion for this project, email alphafs@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Dec 1, 2011 at 7:34 AM

I have the error with this simple test code :

string strBasePath = @"C:\tmp\test.exe";

Alphaleonis.Win32.Filesystem.PathInfo srcInfo = new Alphaleonis.Win32.Filesystem.PathInfo(strBasePath);
Alphaleonis.Win32.Filesystem.PathInfo dstInfo = new Alphaleonis.Win32.Filesystem.PathInfo(strBasePath + ".bak");

Alphaleonis.Win32.Filesystem.File.Move(srcInfo.GetLongPath(), dstInfo.GetLongPath());

The weird thing is that the file is successfully renamed despite the exception.

Dec 1, 2011 at 7:52 AM

That's indeed what the error says.

 But as AlphaFS PInvoke this method from kernel32.dll, I'm surprised to be the only one to have this issue. It would mean that my kernel32.dll has something wrong.

 

Dec 1, 2011 at 9:11 AM

Problem solved.

The signature was

static internal extern bool MoveFileWithProgressW([In] string existingFileName, [In] string newFileName, NativeCopyProgressRoutine lpProgressRoutine, object lpData, [MarshalAs(UnmanagedType.U4)] MoveFileOptions dwFlags);

I replaced it with

static internal extern bool MoveFileWithProgressW([In] string existingFileName, [In] string newFileName, NativeCopyProgressRoutine lpProgressRoutine, IntPtr lpData, [MarshalAs(UnmanagedType.U4)] MoveFileOptions dwFlags);

So I've just modified the type of lpData from object to IntPtr, which seems to be the right type in the native library.

Thanks for your help.

Dec 1, 2011 at 2:54 PM

Just for the record what .NET version is this?

Indeed the bug, as the transacted version of the same method has correct signature :(

Will make a bugfix upload and a new release tonight.

Thank you for reporting it!

Dec 1, 2011 at 3:05 PM

You're welcome :),

I'm using .NET 4.0 ("Full" profile)  32 bits.