Friday, August 19, 2016

Error System.IO.File::Move when using batch process on AX 2012 R3

Problem:

On syntax

System.IO.File::Move(fileName, newFileName);

You get this error when using batch process:

 "System.IO.IOException: The process cannot access the file because it is being used by another process"


Cause:
Possibility
A. Your AOS services is using user which have less security access to folders.
B. You read or access files but not closed yet.


Solution:
A. Add more security access to user who run the AOS services.

B. Closing File

Step-1

Close the files before CodeAccessPermission::revertAssert();

Example:

io              = new TextIO(filenameOp, "r");
io.read();

.....
io.finalized;
io = null;
  
CodeAccessPermission::revertAssert();

Step-2 

Build Generate Increament CIL


Step-3
Close and Open AX.

2 comments:

  1. Thanks for the post and its works for me.

    ReplyDelete
  2. Hello thanks for your post but it does not work for me and I don't understand

    ReplyDelete