Monday, December 20, 2010

WinAPI::getTempFilename() in .NET Business Connector on a x64 machine

A call on the external method GetTempFileNameW on Kernel32 will raise an exception when called from the .NET Business Connector which is running on a x64 machine.

This problem applies at least in AX 2009 (may be on AX 4.0 and AX 3.0 too).

As a workaround you can use code such this:

fileName = System.IO.Path::GetTempFileName(); // returns a filename in the temporary directory

or

fileName = CLRInterop::getAnytypeForObject(System.IO.Path::GetTempPath() )+ curuserid() + int642str(CLRInterop::getAnyTypeForObject(netTime.get_Ticks());


However don't forget to delete the temporary file after, since it makes no sense to let garbage alive.

0 Kommentare:

Post a Comment