Saturday, January 4, 2020

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:

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

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.

No comments:

Post a Comment